我有两个下拉列表.第一个选定的值加载另一个.当我在控制器中有辅助方法时,我该怎么做?
@using (Html.BeginForm())
{
<div>
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td><b>Select a District:</b></td>
<td>@Html.DropDownListFor(m => m.DistrictId, ViewData["DMManagers"] as IEnumerable<SelectListItem>, "Select One")</td>
</tr>
<tr>
<td><b>Select a TM:</b></td>
<td>@Html.DropDownListFor(m => m.TMId, ViewData["TMManagers"] as IEnumerable<SelectListItem>, "Select One")</td>
</tr>
</table>
</div>
}
private void LoadDistrictManagers()
{
var _DMS = (from c in SessionHandler.CurrentContext.ChannelGroups
join cgt in SessionHandler.CurrentContext.ChannelGroupTypes on c.ChannelGroupTypeId equals cgt.ChannelGroupTypeId
where cgt.Name == "District Manager"
select new { c.ChannelGroupId, c.Name }).OrderBy(m => m.Name);
ViewData["DMManagers"] = new SelectList(_DMS, "ChannelGroupId", "Name");
}
private void LoadTerritoryManagers(int …
Run Code Online (Sandbox Code Playgroud) 它在chrome,firefox和IE8中运行良好.但在IE7上出现错误.这是我的jquery onchange事件.
$('select#NationId').change(function () {
var nationId = $(this).val();
$.ajax({
url: 'LoadAreas',
type: 'POST',
data: JSON.stringify({ nationId: nationId }),
dataType: 'json',
contentType: 'application/json',
success: function (data) {
$('select#AreaId').get(0).options.length = 0;
$('select#AreaId').append('<option value="0">Select All</option>');
$.each(data, function (val, Areas) {
$('select#AreaId').append('<option value="' + Areas.Id + '">' + Areas.Name + '</option>');
});
}
});
});
Run Code Online (Sandbox Code Playgroud)
调节器
[HttpPost]
public ActionResult LoadAreas(int nationId)
{
var _Areas = (from c in SessionHandler.CurrentContext.ChannelGroups
join cgt in SessionHandler.CurrentContext.ChannelGroupTypes on c.ChannelGroupTypeId equals cgt.ChannelGroupTypeId
where cgt.Name == "Area" && c.ParentChannelGroupId …
Run Code Online (Sandbox Code Playgroud) 我尝试运行报告时收到错误.问题出在这里:model.Referring = Math.Round(_newSurveyResult.Select(m => string.IsNullOrEmpty(m.Question1) ? 0 : Double.Parse(m.Question1)).Average());
public class SummaryDetails
{
public int ChannelId { get; set; }
public int ChannelGroupId { get; set; }
public string Question1 { get; set; }
public string Question2 { get; set; }
public string Question3 { get; set; }
public string Question4 { get; set; }
public int OrganizationId { get; set; }
}
public ActionResult AreaManager(AreaManagerModel model)
{
model.ShowCustomerReport = false;
model.ShowSurveyReport = true;
LoadModelVariablesonPostBack(model, 8);
var _newSurveyResult = …
Run Code Online (Sandbox Code Playgroud) 我想让MVC 3中的文本框显示为标签.我仍然显示边界的代码.
<p>@Html.TextBoxFor(m => m.PostcardsperWeek, new Dictionary<string, object>() {
{ "id", "txtPostcardPerWeek" },
{ "readonly", "true" },
{"class", "TextBoxAsLabel"} })
</p>
Run Code Online (Sandbox Code Playgroud)
CSS:
.TextBoxAsLabel
{
border: none;
background-color: #fff;
background: transparent;
}
Run Code Online (Sandbox Code Playgroud) 我不知道如何实现这一目标.我想在视图中使用foreach循环以表格格式显示数据.此数据将来自linq查询,该查询使用3-4个表并选择要显示的不同字段.不知道如何返回这个,因为我得到一个匿名类型错误.
var info = from s in context.LennoxSurveyResponses
join customers in context.Customers on s.SurveyCode equals customers.SurveyCode
join lists in context.CustomerLists on customers.ListId equals lists.ListId
join dealer in context.Channels on lists.ChannelId equals dealer.ChannelId
where dealer.ChannelId == id
select new
{
ResponseId = s.ResponseId,
CustomerFirstName = customers.FirstName,
CustomerLastName = customers.LastName,
CustomerTestimonial = s.Question5Answer
};
Run Code Online (Sandbox Code Playgroud)
我的模型必须声明什么才能传递给视图?