0

我创建了一个剑道弹出窗口,它从内容中的控制器加载下拉选择。我还添加了一个更改事件,该事件获取所选索引的 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>&nbsp;" +
                   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>&nbsp;</td>" +
                  "<td>" +
                  "<div id='divButtons' class='createNew-buttonContainer'>" +
                        "<button id='createNewLink-cancel' class='k-button saveNewButtons' >Cancel</button>&nbsp;" +
                        "<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")
        )
    }
   }
 }
}
4

1 回答 1

0

我还没有实现你的代码,所以这只是解释你所拥有的猜测。看起来你没有对调用的响应做任何事情来获取部分视图。在您的 javascript onSelect 方法中,调用成功时没有任何反应。这意味着您正在控制器上调用 GetUserFields 操作,并且它正在返回呈现的部分视图,但您的 javascript onSelect 方法实际上忽略了结果。

您可能需要在 ajax 调用的成功部分添加一些逻辑。

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"
        success: function(){
            // attach the response to the existing DOM
        }
    });
}
于 2014-10-24T13:43:14.367 回答