양식, 두 개의 텍스트 상자 및 제출 단추를 포함하는 사용자 권한 부여에 대한 제어 권한이 있습니다. 이 컨트롤은 RenderAction 메서드를 통해 마스터 페이지에 포함됩니다. 등록 페이지 (RenderBody 메서드를 통해 뷰에 포함 된 뷰)도 양식과 함께 있습니다. 등록 양식에서 데이터를 제출하면 로그인 컨트롤이 트리거되고 처리기 (POST 데이터 처리를위한 컨트롤러 메서드)가 호출됩니다. 아래에서 권한 부여를위한 컨트롤러 메소드를 볼 수 있습니다. 다른 양식의 데이터를 제출 한 후 POST 데이터를 로그인 컨트롤로 보내지 못하게하려면 어떻게해야합니까?ASP.NET MVC 3 양식 제출 RenderAction 처리기에 영향을 미침
[HttpPost]
public RedirectResult LogIn(AuthViewModel authResult)
{
if (ModelState.IsValid)
{
userService.LogInUser(authResult.Login, authResult.Password, Request.UserHostAddress);
}
else
{
TempData["AuthMessage"] = GetValidationMessage();
}
string redirectUrl = "/";
if (Request.UrlReferrer != null)
{
redirectUrl = Request.UrlReferrer.AbsoluteUri.ToString();
}
return Redirect(redirectUrl);
}
[HttpGet]
[ChildActionOnly]
public PartialViewResult LogIn()
{
if (userService.IsUserLoggedIn())
{
User currentUser = userService.GetLoggedInUser();
ViewBag.LoggedInMessage = currentUser.FullName + "(" + currentUser.Login + ")";
}
return PartialView("AuthControl");
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>@ViewBag.Title</title>
</head>
<body>
<div>
<div id="header">
<div>
<div>
@{Html.RenderPartial("SearchControl");}
</div>
</div>
</div>
<div id="right_menu">
<div>
@{Html.RenderAction("LogIn", "Navigation");}
</div>
@{Html.RenderAction("Menu", "Navigation");}
<div>
@{Html.RenderAction("Index", "Messages");}
</div>
<div>
@{Html.RenderAction("TagCloud", "Navigation");}
</div>
</div>
<div id="main_content">
@RenderBody()
</div>
<div id="footer">
</div>
</div>
</body>
</html>
AuthControl :
가@model AuthViewModel
<div class="rounded-corners auth-panel">
@if (ViewBag.LoggedInMessage == null)
{
<div class="auth-container">
@using (Html.BeginForm("LogIn", "Navigation"))
{
<div>
<label for="Login">
Login:
</label>
@Html.TextBoxFor(m => m.Login, new { @class="middle-field"})
</div>
<div>
<label for="Password">
Password:
</label>
@Html.PasswordFor(m => m.Password, new { @class="middle-field"})
</div>
<div class="in-center">
<input type="image" src="@Url.Content("~/Content/Images/submit.png")"/>
</div>
}
</div>
<div class="error-msg">
@if (TempData["AuthMessage"] != null)
{
@Html.Raw(TempData["AuthMessage"].ToString())
}
@Html.ValidationSummary()
</div>
<div class="small-nav-message">
<a href="#" class="registration-link">Registration</a>
</div>
}
</div>
등록 페이지 : 등록 감안
RegistrationViewModel
@{
ViewBag.Title = "Registration";
}
@if (TempData["RegistrationFinished"] == null || !(bool)TempData["RegistrationFinished"])
{
<div class="post content-holder">
<div class="fields-holder">
<div >
<div class="error-msg">
@if (TempData["ValidationMessage"] != null)
{
@Html.Raw(TempData["ValidationMessage"].ToString())
}
</div>
@using (Html.BeginForm())
{
<span>
Email:
</span>
<span>
@Html.TextBoxFor(v => v.Email)
</span>
<span>
Password:
</span>
<span>
@Html.PasswordFor(v => v.Password)
</span>
<input type="submit" value="Register"/>
}
</div>
</div>
</div>
}
else
{
<div>
Activation link was sent to your email.
</div>
}
[여기에 명시된 바와 같이] (http://www.w3.org/MarkUp/html3/forms.html) "양식 요소를 중첩 할 수 없습니다." – Igarioshka
제 경우에는 양식이 중첩되지 않습니다. – eternity
마크 업을 게시 하시겠습니까? – Igarioshka