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>