我想顯示有關用戶註冊狀態的信息。它應該顯示在每個視圖上,但我認爲,將該代碼寫入約20次是一個糟糕的主意。順便說一句,這是代碼,它的工作原理,我保證:如何在每個視圖中顯示相似的信息?
查看/ RegistrationInfo:
<table width="95%" border="0" cols="2">
<tr>
<td width="50%" height="124"><h2><strong>Simple Blog </strong></h2></td>
<td width="50%" height="124">
@if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
{
using (Html.BeginForm("LogOff", "Account"))
{
<table width="95%" height="86" border="0">
<tr>
<td width="50%" valign="middle">Hello, @System.Web.HttpContext.Current.User.Identity.Name</td>
<td width="50%" valign="middle" align = "right"><input type="submit" value="Exit" /></td>
</tr>
</table>
}
}
else
{
using (Html.BeginForm("LogIn", "Home"))
{
<table width="95%" height="86" border="0">
<tr>
<td width="45%" valign="bottom">Login:</td>
<td width="45%" valign="bottom">Password:</td>
<td width="10%"></td>
</tr>
<tr>
<td width="45%">
<p>
<input type="text" name="login" />
</p>
</td>
<td width="45%">
<p>
<input type="password" name="password" />
</p>
</td>
<td width="10%" align="left">
<input type="submit" value="Enter" />
</td>
</tr>
<tr>
<td width="45%" valign="top">
@Html.ActionLink("Register", "Register", "Account")
</td>
</tr>
</table>
}
}
</td>
</tr>
</table>
<hr align="left" width="100%" size="2" />
正如你所看到的,這種觀點並不需要是強類型...和我不知道,我是否應該修改任何控制器(因爲所有信息都存儲在HTML上下文中)以及如何修改。我試着打電話給
@Html.RenderAction("RegistrationInfo", "Home");
或 @ Html.RenderPartial( 「RegistrationInfo」, 「家」);
每次我收到編譯錯誤包含無效參數應用
非常感謝您 – Eugene