我创建了一个剑道弹出窗口,它从内容中的控制器加载下拉选择。我还添加了一个更改事件,该事件获取所选索引的 id 并将其传递给控制器并返回带有文本框的部分视图,该文本框可能会根据选择而更改,因此文本框的创建需要是动态的。我尝试添加 Html.Partial(_myPartialView),但结果未呈现。我究竟做错了什么?
@(Html.Kendo().Window()
.Name("userSetupWindow")
.AppendTo("#useAcct")
.Width(600)
.Height(600)
.Scrollable(false)
.Modal(true)
.Title("New Setup")
.Actions(actions => actions.Refresh().Close())
.Draggable()
.Content("<section id='CreateLink' class = 'saveNewDialog-screen'>" +
"<div class='saveNewLinkDialog' style='border: none;' >" +
"<div style='border: none;'>" +
"<table>" +
"<tr style='height: 30px;'>" +
"<td style='width: 30%; vertical-align: top;'>" +
"<div id='divAccounts' class ='createNew'> " +
"<label id='lbList' for='createNew' class='CreateNew-Label'>Select New</label> " +
Html.Kendo().DropDownList()
.Name("userList")
.DataSource(source => source.Read(read => read.Action("GetUsers", "UserAcctMgmt")
.Data("getSelectedId")
.Type(HttpVerbs.Post)))
.DataTextField("UserName")
.DataValueField("Id")
.Value("Id")
.SelectedIndex(0)
.Events(events => events.DataBound("onDropDownDataBound"))
.Events(events => events.Change("onSelect")) +
"</div>" +
"</td>" +
"</tr>" +
"<tr style='height: 30px;'>" +
"<td> </td>" +
"<td>" +
"<div id='divButtons' class='createNew-buttonContainer'>" +
"<button id='createNewLink-cancel' class='k-button saveNewButtons' >Cancel</button> " +
"<button id='createNewLink-save' class='k-button saveNewButtons'>Save</button>" +
"</div>" +
"</td>" +
"</tr>" +
"<tr style='height: 80px;>" +
"<td>" +
"<div id='div-textboxes'>" +
Html.Partial(_dynamicPartialView)
"</div>" +
"</td>" +
"</tr>" +
"</table>" +
"</div>" +
"</div>" +
"</section>'"
).Events(events => events.Close("onPopupClose"))
在控制器中:
[HttpPost]
public ActionResult GetUserFields(string Id)
{
if (!string.IsNullOrWhiteSpace(Id))
{
var fields = GetuserFields(int.Parse(Id));
var model = new FieldModel
{
Fields = fields
};
return PartialView("_dynamicPartialView", model);
}
return null;
}
Jquery 工作,它把我带到部分视图
function onSelect(e) {
e.preventDefault();
var selectedId = this.dataItem(e.item).id;
$.ajax({
url: "@Url.Action("GetUserFields", "UserModel")",
type: 'POST',
cache: false,
data: JSON.stringify({ Id: selectedId }),
contentType: "application/json; charset=utf-8",
dataType: "json"
});
}
这是局部视图(_dynamicPartialView)
@model Models.UserFieldModel
@using Kendo.Mvc.UI
@if (Model != null)
{
foreach (var item in Model.UserFields)
{
<p>@item.FieldName</p>
if (item.FieldType.ToString().ToUpper() == "TEXTBOX")
{
if (item.IsCaseSensitiveField)
{
@(Html.Kendo().TextBox()
.Name("caseSensitive")
)
}
else
{
@(Html.Kendo().TextBox()
.Name("textInput")
)
}
}
}
}