【发布时间】:2017-09-29 21:33:20
【问题描述】:
我有一个视图 A、视图 B 和一个视图 _C。
View _C 是在 View A 和 B 内渲染的局部视图:
查看 A:
<div style="margin-top:20px;">
<div>
@Html.Partial("~/Views/_C.cshtml", null, new ViewDataDictionary { { "WithRedirect", "true" } });
</div>
</div>
查看 B
<div style="margin-top:20px;">
<div>
@Html.Partial("~/Views/_C.cshtml", null, new ViewDataDictionary { { "WithRedirect", "false" } });
</div>
</div>
视图C(部分视图)-代码片段:
.
.
<td style="padding-bottom: 8px;">
@Html.EditorFor(model => model.CurrentPassword, new { htmlAttributes = new { @class = "form-control k-textbox checkError", placeholder = "Enter current password" } })
</td>
.
.
渲染局部视图时,我需要设置一个标志“WithRedirect”以便稍后在控制器中引用它来决定是否需要重定向到另一个视图:
string withRedirect = this.ViewData.ContainsKey("WithRedirect") ? this.ViewData["WithRedirect"].ToString() : string.Empty;
if(WithRedirect.Equals("true") return Redirect(returnUrl ?? Url.Action("Index", "Page1")); 别的 return Redirect(returnUrl ?? Url.Action("Index", "Page2"));
调试控制器时,WithRedirect变量为空字符串。
我做错了什么,解决办法是什么?
【问题讨论】:
标签: asp.net-mvc-4 asp.net-mvc-partialview