我想创建一个控件,允许用户使用 ASP.NET MVC4 在管理站点的主页上显示/隐藏 div 框。例如,如果用户从管理站点选择禁用 div 框,当他返回主页时 div 框将消失,显示 div 框也是如此。
我整天都在寻找正确的答案,但仍然没有找到最佳答案。而且我真的不知道如何在管理站点和主页之间链接。
以下是我的管理页面:
<div class="section-header">
<div class="title">
<img src="@Url.Content("~/Administration/Content/images/ico-configuration.png")" alt="" />
@T("Manage LoginBox")
</div>
<div class="options">
<input type="submit" name="save" class="t-button" value="@T("Admin.Common.Save")" />
</div>
</div>
<script type="text/javascript">
@*$(document).ready(function () {
$("#@Html.FieldIdFor(model => model.EnableLoginBoxAtHomePage)").click(toggleLoginBoxEnabled);
toggleLoginBoxEnabled();
});*@
function toggleLoginBoxEnabled() {
if ($('#@Html.FieldIdFor(model => model.EnableLoginBoxAtHomePage)').is(':checked')) {
Response.Write("Surprise");
$('#pnlShowLoginBoxAtHomePage').show();
}
else {
$('#pnlShowLoginBoxAtHomePage').hide();
}
}
function toggleLoginBoxDisabled() {
if ($('#@Html.FieldIdFor(model => model.DisableLoginBoxAtHomePage)').is(':checked')) {
$('#pnlHideLoginBoxAtHomePage').hide();
}
else {
$('#pnlHideLoginBoxAtHomePage').show();
}
}
</script>
@Html.ValidationSummary(false)
<table class="adminContent">
<tr id="pnlShowLoginBoxAtHomePage" onclick="toggleLoginBoxEnabled">
<td class="adminTitle">
@Html.LabelFor(model => model.EnableLoginBoxAtHomePage)
</td>
<td class="adminData">
@Html.EditorFor(model => model.EnableLoginBoxAtHomePage)
@Html.ValidationMessageFor(model => model.EnableLoginBoxAtHomePage)
</td>
</tr>
<tr id="pnlHideLoginBoxAtHomePage" onclick="toggleLoginBoxDisabled">
<td class="adminTitle">
@Html.LabelFor(model => model.DisableLoginBoxAtHomePage)
</td>
<td class="adminData">
@Html.EditorFor(model => model.DisableLoginBoxAtHomePage)
@Html.ValidationMessageFor(model => model.DisableLoginBoxAtHomePage)
</td>
</tr>
</table>
}
这是我想在主页显示/隐藏的 div 框:
<div class="block block-loginbox" >
<div class="title">
<strong>@T("Login")</strong>
</div>
<div class="clear">
</div>
<div class="listbox" @*id="myloginbox"*@>
<fieldset class="form-fields returning-wrapper">
<legend>@T("Account.Login.ReturningCustomer")</legend>
<dl>
@using (Html.BeginForm("Login","Customer"))
{
<dd class="message-error">
@Html.ValidationSummary(true, T("Account.Login.Unsuccessful").Text)
</dd>
<dt>
@Html.LabelFor(m => m.Email): </dt>
<dd>
@Html.TextBoxFor(m => m.Email, new { @class = "email", autofocus = "autofocus" })
@Html.ValidationMessageFor(m => m.Email)
</dd>
<dt>
@Html.LabelFor(m => m.Password): </dt>
<dd>
@Html.PasswordFor(m => m.Password, new { @class = "password" })
@Html.ValidationMessageFor(m => m.Password)
</dd>
<dd>
@Html.CheckBoxFor(m => m.RememberMe)
@Html.LabelFor(m => m.RememberMe)
</dd>
<dd class="forgot-password">
@Html.RouteLink(T("Account.Login.ForgotPassword").Text, "PasswordRecovery")
</dd>
<dd class="buttons">
<input class="button-1 login-button" type="submit" onclick="location.href='@registerUrl'" value="@T("Account.Login.LoginButton")" />
</dd>
}
</dl>
</fieldset>
<div class="clear">
</div>
</div>
</div>