我正在尝试创建一个使用 KENDO UI Dropdown 的应用程序。问题是我想将视图中的值更新到数据库中。在下拉列表中选择任何值时,与其关联的 ID 应传递到控制器以进行所需的数据库更新。但是在这里,下拉列表中任何选择的 ID 都会将“null”作为值传递给控制器。
我的观点
@using Kendo.Mvc.UI
@model ExamplekendoDropdown.Models.FacilityGroup
@{
ViewBag.Title = "FacilityGroup";
}
<h2>FacilityGroup</h2>
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<legend>FacilityGroup</legend>
<div id="RegionName" class="editor-label">
@Html.LabelFor(model => model.RegionId)
</div>
<div class="editor-field">
@* @Html.EditorFor(model => model.RegionName)*@
@(Html.Kendo().DropDownList()
.Name("Region")
.DataTextField("RegionName")
.DataValueField("RegionId")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetRegion", "Fill");
});
})
)
@Html.ValidationMessageFor(model => model.RegionId)
</div>
<div id="Rest">
@*<form method="post" action='@Url.Action("Submit")' style="width:45%">
<div>
@(Html.Kendo().Upload()
.Name("files")
)
<p>
<input type="submit" value="Submit" class="k-button" />
</p>
</div>
</form>*@
<div class="editor-label">
@Html.LabelFor(model => model.FaclityGroupName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.FaclityGroupName)
@Html.ValidationMessageFor(model => model.FaclityGroupName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.status)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.status)
@Html.ValidationMessageFor(model => model.status)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.CreationDate)
</div>
<div class="editor-field">
@* @Html.EditorFor(model => model.CreationDate)*@
@(Html.Kendo().DatePicker()
.Name("datepicker")
.Value("17/08/2011")
.HtmlAttributes(new { style = "width:150px" })
)
@Html.ValidationMessageFor(model => model.CreationDate)
</div>
<p>
<input type="submit" value="Create" />
</p>
</div>
</fieldset>
}
<div>
@Html.ActionLink("See the List", "List")
</div>
<div>
@Html.ActionLink("Back to List", "About")
</div>
<script type="text/javascript">
$(document).ready(function () {
$("#RegionName").click(function () {
$("#Rest").show();
});
});
</script>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
控制器 :-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ExamplekendoDropdown.Models;
namespace ExamplekendoDropdown.Controllers
{
public class FacilityGroupController : Controller
{
//
// GET: /FacilityGroup/
public ActionResult FacilityGroup()
{
return View();
}
[HttpPost]
public ActionResult FacilityGroup(FacilityGroup objadd)
{
AMIEntities1 obj1 = new AMIEntities1();
Facility objtbl = new Facility();
objtbl.RegionId = Convert.ToInt16(objadd.RegionId);
objtbl.FaclityGroupName = objadd.FaclityGroupName.ToString();
objtbl.Status = objadd.status;
objtbl.CreationDate = objadd.CreationDate;
obj1.AddToFacilities(objtbl);
obj1.SaveChanges();
obj1.AcceptAllChanges();
return View();
}
}
}
请帮助!