0

javascript中的代码

function SubmitQuery(Org_UID) {

        var ddlProduct_No = $("#Org_UID");
        $.ajax({
            type: 'POST',
            url: '@Url.Action("ShowNewProfessionalWindow", "UpdateOrganizationUID")',
            dataType: "html",
            data: {
                countryno: $("#Org_UID").val() }

我的控制器

    [HttpPost]
    public ActionResult ShowNewProfessionalWindow(string countryno)
    {
          UpdateOrganizationUIDViewModel model = new UpdateOrganizationUIDViewModel();
            //model.Org_UID = OrgUID;
            model.org_name_long = "test";
            model.org_name_short = "test";


            return RedirectToAction("Index", model);
        }

如何使用 jquery 返回模型的值以查看?

4

1 回答 1

0

利用JsonResult

更改您的代码并返回JsonResult,所以使用

return Json(model);

代替

return RedirectToAction("Index", model);

如果要返回查看使用

首先,您可以创建一个方法,它将接受ViewNameModel返回 HTML 字符串

public static string RenderRazorViewToString(ControllerContext controllerContext, string viewName, object model)
{
    controllerContext.Controller.ViewData.Model = model;
    using (var sw = new StringWriter())
    {
        var viewResult = ViewEngines.Engines.FindPartialView(controllerContext, viewName);
        var viewContext = new ViewContext(controllerContext, viewResult.View,
                controllerContext.Controller.ViewData, controllerContext.Controller.TempData, sw);
        viewResult.View.Render(viewContext, sw);
        viewResult.ViewEngine.ReleaseView(controllerContext, viewResult.View);
        return sw.GetStringBuilder().ToString();
    }
}

用法也你必须返回JsonResult而不是PartialViewResult

public JsonResult yourpartialviewresult()
{
    return Json(new
            {
                data = RenderRazorViewToString(this.ControllerContext, "partialview", model)
            });
}
于 2013-09-25T13:57:45.773 回答