1

MVC3のビューに次のjQueryコードがあります。success関数で渡されたJSONオブジェクトに応じてOffshoreECore、div()に部分ビュー(named)をロードしたいと思います。#Formコードは次のとおりです。

var inputParamtrs = { 'HeadId': $('#ExpenseId').val(), MProjid': $('#MProjid').val() };
$.ajax({
    type: "POST",
    url: "/Expenses/Edit",
    data: inputParamtrs,
    success:  function (json) {
        ('#Form').load('@Url.Action("OffShoreECore", *What comes here ?!?*)');
    }

ありがとう。

4

2 に答える 2

2

The second parameter of load() is the data which should be sent to the specified URL along with the request. To send your JSON string, try this:

success:  function (json) {
    $('#Form').load('@Url.Action("OffShoreECore")', json);
}

You example code is also missing a ' delimiter from the second key in inputParamtrs and the $ from the selector in success, but I guess they're just typos.

于 2012-05-28T12:49:25.677 に答える
0
$.getJSON("/Expenses/Edit",
    {
        HeadId: $('#ExpenseId').val(), 
        MProjid: $('#MProjid').val() 
    },
    function (data) {
        elementForResult.innerHTML = data;
    });

コントローラーで:

public JsonResult Edit(int HeadId, int MProjid)
    {
        ...
        var result = SerializeControl("~/Views/Expenses/Edit.cshtml", null);
        return Json(result, JsonRequestBehavior.AllowGet);
    }

private string SerializeControl(string controlPath, object model)
    {
        var control = new RazorView(ControllerContext, controlPath, null, false, null);
        ViewData.Model = model;
        var writer = new HtmlTextWriter(new StringWriter());
        control.Render(new ViewContext(ControllerContext, control, ViewData, TempData, writer), writer);
        string value = writer.InnerWriter.ToString();
        return value;
    }
于 2012-05-28T12:52:18.530 に答える