我在 ASP.NET- MVC帮助程序中遇到问题我有一个表单,可以将POST付诸实施注册事件需要一个TypeOccurrenceID,我正在尝试使用Html.DropDownListFor()获取此值,但是在发布表单时这不起作用,参数中的Occurrence过去没有与所选 OccurrenceType 对应的 OccurrenceTypeId在下拉列表中
有人有同样的问题吗?
这是我的控制器动作
[HttpPost]
public ActionResult Create(Occurrence occurrence)
{
if (ModelState.IsValid)
{
try
{
db.Add<Occurrence>(occurrence);
return new HttpStatusCodeResult(200);
}
catch (Exception)
{
return new HttpStatusCodeResult(400);
}
}
return new HttpStatusCodeResult(400);
}
这是我的看法
@using Common.Util
@using Common.Util.Configuration
@using CafData
@model Occurrence
<div class="box-form">
@using (Ajax.BeginForm("Create", "Occurrence",
new AjaxOptions
{
OnSuccess = "OnSuccess()",
OnFailure = "OnFailure()"
}))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
@*Area*@
<div class="row-fluid details-field">
@(Html.Kendo().DropDownList()
.Name("areas")
.HtmlAttributes(new { style = "width:300px" })
.OptionLabel("Selecione uma area...")
.DataTextField("Description")
.DataValueField("IdArea")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("readAreasForDropDown", "Area");
});
})
)
@*Occurrence type*@
@(Html.Kendo().DropDownListFor(m => m.OccurrenceTypeId)
.Name("occurrencetype")
.HtmlAttributes(new { style = "width:300px" })
.OptionLabel("Select a occurrence type...")
.DataTextField("Description")
.DataValueField("OccurrenceTypeId")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("lerOccurrenceTypeForDropDown",
"OccurrenceType").Data("filterArea").
Type(HttpVerbs.Post);
})
.ServerFiltering(true);
})
.Enable(false)
.AutoBind(false)
.CascadeFrom("areas")
)
<script>
function filterArea() {
return {
id: $("#areas").val()
};
}
</script>
<button class="k-button">Save</button>
}
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
对不起英语不好!