0

別のコントローラーから部分ビューを取得するために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);
}

@Html.EditorFor(model => model.zipcode,@ajax_insert)を試しました が、うまくいきませんでした。

4

1 に答える 1

0

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>
于 2013-02-25T20:23:02.493 に答える