查看:
@using (Ajax.BeginForm("CreateFolder", "Folder", FormMethod.Post, new AjaxOptions { OnSuccess = "CreateFolderSuccess" }))
{
Code blabla..
}
过滤
这样的事情......?
filterContext.Result = new JsonResult
{
ViewString = this.RenderViewToString("~/Views/Folder/ReadFolder.cshtml", null),
isRedirect = true
};
脚本成功:
function CreateFolderSuccess(result) {
if (result.isRedirect) {
$('#LogInReload').html(result.ViewString);
}
else {
$('#CreateReload').html(result);
}
}
所以我在不同的结果上返回不同的部分观点。
我需要帮助:
我真的不知道如何从FILTERCONFIG返回部分视图+参数。我之前在我的控制器中完成过但不是这样的。我很乐意帮助..谢谢
更新1:
忘了我的分机:
public static string RenderViewToString(this Controller controller, string viewName, object model)
{
using (StringWriter writer = new StringWriter())
{
ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(controller.ControllerContext, viewName);
controller.ViewData.Model = model;
ViewContext viewCxt = new ViewContext(controller.ControllerContext, viewResult.View, controller.ViewData, controller.TempData, writer);
viewCxt.View.Render(viewCxt, writer);
return writer.ToString();
}
}