【问题标题】:mvc3 ajax prepoluate textboxmvc3 ajax 预填充文本框
【发布时间】:2013-02-25 19:54:08
【问题描述】:

我有一个控制器,它使用 ajax.actionlink 来从另一个控制器获取部分视图。我的问题是如何使用 ajax partialview 的结果在我的主要操作中填写文本框

这是我正在处理的视图对应于这个视图

@Ajax.ActionLink("Find location", "getzipcode",
new AjaxOptions
{
    UpdateTargetId = "ajax_insert",
    InsertionMode = InsertionMode.Replace,
    HttpMethod = "GET"
});

<div id="ajax_insert">

</div>

@using (Html.BeginForm("create", "service", FormMethod.Post))
{

    // fill Ajax code in this EditFor Result
    @Html.EditorFor(model => model.zipcode)

}

正如您在上面看到的那样,ajax 只是请求一个名为 getzipcode 的局部视图,它只是链接到此操作

public PartialViewResult getzipcode()
{
    var zipco = (from s in db.servicers where s.zipcode == 32839 select s);

    return PartialView("_review", zipco);
}

ajax 工作正常,我只是在将邮政编码插入 EditFor 框时遇到了困难,我也试过了 @Html.EditorFor(model => model.zipcode,@ajax_insert) 但它不起作用。

【问题讨论】:

  • 请做一些工作以使您的代码更具可读性。您的代码 sn-ps 中完全有太多不必要的空间。

标签: ajax asp.net-mvc-3 data-binding


【解决方案1】:

你可以使用onSuccess回调函数

    @Ajax.ActionLink("Find location", "getzipcode",
    new AjaxOptions
    {
        UpdateTargetId = "ajax_insert",
        InsertionMode = InsertionMode.Replace,
        HttpMethod = "GET",
        OnSuccess = "fillTextBox"
    });

    <script type="text/javascript>
     function fillTextBox(){
      //Use jquery to fill your text box
     }
    </script>

【讨论】:

  • @user1591668 感谢您接受我的回答,不客气。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-09-29
  • 1970-01-01
  • 1970-01-01
  • 2013-08-14
  • 1970-01-01
  • 2011-06-21
  • 2013-04-27
相关资源
最近更新 更多