gpt4 book ai didi

kendo-ui - 剑道 DropDownListFor() 与 ASP.NET-MVC

转载 作者:行者123 更新时间:2023-12-04 09:41:01 25 4
gpt4 key购买 nike

我有一个问题进入 ASP.NET-MVC 助手
我有一个表单可以让 POST 付诸实现 **create
Controller 出现 传递 类型的参数发生 对应于 型号 表格 已插入,为了注册,需要 类型出现ID ,我正在尝试使用 获取此值Html.DropDownListFor() ,但是当表单发布时这不起作用,出现 参数中的过去没有
与 DropDownList 中选择的 OccurrenceType 对应的 OccurrenceTypeId

有人有同样的问题吗?

这是我的 Controller 操作

    [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")
}

对不起英语不好!

最佳答案

问题是下拉列表的名称,它必须与要绑定(bind)的模型的属性名称相同。

示例:

 @(Html.Kendo().DropDownListFor(m => m.OccurrenceTypeId)
.Name("OccurrenceTypeId")

备选:

使用 DropDownListFor 时实际上不需要 name 属性。因此,只需删除此行也可以:
 .Name("occurrencetype")

关于kendo-ui - 剑道 DropDownListFor() 与 ASP.NET-MVC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16813076/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com