weixin_33686714 2013-02-25 19:54 采纳率: 0%
浏览 41

mvc3 ajax预填充文本框

I have a controller that uses ajax.actionlink in order to get a partial view from another controller. My question is how can I use the result from that ajax partialview to fill in a textbox in my main action .

This is the view i'm working on corresponds to this view

@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)

}

as you can see above that ajax simply request's a partial view called getzipcode which just links to this action

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

    return PartialView("_review", zipco);
}

The ajax works correctly, im just stumped on inserting the zipcode into the EditFor box as well I tried @Html.EditorFor(model => model.zipcode,@ajax_insert) but it did not work.

  • 写回答

1条回答 默认 最新

  • weixin_33681778 2013-02-25 20:23
    关注

    You can make use of onSuccess callback function

        @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>
    
    评论

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条