Kendo ui 无法从主视图检索部分视图中的隐藏元素
我已经在MVC5视图上实现了剑道组合框,并希望根据模型中的值对组合框进行过滤。我需要从我的模型中检索值。在我的局部视图中,我目前已将该值绑定到名为CountryCode的隐藏字段。脚本在我的主视图中。尝试访问隐藏字段时收到未定义的错误消息。模型中肯定会填充CountryCodeKendo ui 无法从主视图检索部分视图中的隐藏元素,kendo-ui,asp.net-mvc-5,kendo-asp.net-mvc,Kendo Ui,Asp.net Mvc 5,Kendo Asp.net Mvc,我已经在MVC5视图上实现了剑道组合框,并希望根据模型中的值对组合框进行过滤。我需要从我的模型中检索值。在我的局部视图中,我目前已将该值绑定到名为CountryCode的隐藏字段。脚本在我的主视图中。尝试访问隐藏字段时收到未定义的错误消息。模型中肯定会填充CountryCode @using System.Collections @model CC.GRP.MCRequest.ViewModels.RequestStatusUpdateViewModel @{ Layout = nu
@using System.Collections
@model CC.GRP.MCRequest.ViewModels.RequestStatusUpdateViewModel
@{
Layout = null;
}
<div class="k-popup-edit-form k-window-content k-content" >
<div class="k-edit-form-container">
@Html.HiddenFor(model => model.CountryCode)
<div class="editor-label">
@Html.LabelFor(model => model.RequestID)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.RequestID, new { htmlAttributes = new { @readonly = "readonly" } })
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ProjectName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ProjectName, new { htmlAttributes = new { @readonly = "readonly" } })
</div>
<div class="editor-label">
@Html.LabelFor(model => model.RequestStatus)
</div>
<div class="editor-field">
@(Html.Kendo().ComboBoxFor(model => model.RequestStatusCode)
.HtmlAttributes(new { style = "width:100%" })
.DataTextField("Status")
.Placeholder("Select...")
.DataValueField("RequestStatusCode")
.AutoBind(false)
.Filter("contains")
.DataSource(dataSource => dataSource
.Read(read =>
{
read.Action("GetRequestStatus", "Request")
.Type(HttpVerbs.Post)
.Data("GetCountryCodeFilter");
}).ServerFiltering(true)
)
)
</div>
@Html.ValidationMessageFor(model => model.RequestStatusCode, "", new { @class = "text-danger" })
</div>
</div>
主视图中的脚本
public ActionResult RequestStatus(int requestId, string projectName, string countryCode)
{
RequestStatusUpdateViewModel reqeustStatusUpdateViewModel = new RequestStatusUpdateViewModel();
reqeustStatusUpdateViewModel.RequestID = requestId;
reqeustStatusUpdateViewModel.ProjectName = projectName;
reqeustStatusUpdateViewModel.CountryCode = countryCode;
if (!ModelState.IsValid)
{
// return View("NewRequestView", Mapper.Map<RequestStatusViewModel>(newReqeustViewModel));
return null;
}
return View("_RequestStatusView", Mapper.Map<RequestStatusUpdateViewModel>(reqeustStatusUpdateViewModel));
}
function GetCountryCodeFilter() {
alert("Hello");
alert($('#CountryCode').val());
return { countryCode: $('#CountryCode').val() }
};
我假设这是剑道网格中的弹出窗口。问题在于,当单击任何行时,视图都会被序列化并发送到弹出窗口。它不像您在MVC中所期望的那样绑定数据——它每次都发送相同的序列化数据。看 因此,将隐藏更改为使用kendo的MVVM绑定,以便每个实例从网格行获取值。(CountryCode需要存在于网格的数据源中): 或者你可以使用:
<input type="hidden" name="CountryCode" id="CountryCode" data-bind = "value: CountryCode"/>
function GetCountryCodeFilter() {
alert("Hello");
alert($('#CountryCode').val());
return { countryCode: $('#CountryCode').val() }
};
@Html.HiddenFor(x => x.CountryCode, new { data_bind = "value: CountryCode" }) // underscore becomes dash
<input type="hidden" name="CountryCode" id="CountryCode" data-bind = "value: CountryCode"/>