Я создаю страницу регистрации регистра в asp mvc и, как мне нужно, эта страница имеет две модели и два действия формы. всякая вещь в порядке, но проверка. модели являются:ASP.NET MVC Несколько форм на одной странице: проверка не работает
public class Account_Index_ViewModel
{
public UserAccount_Login_ViewModel userAccount_Login_ViewModel { get; set; }
public UserAccount_Register_ViewModel userAccount_Register_ViewModel { get; set; }
}
public class UserAccount_Login_ViewModel
{
[Required]
[DataType(DataType.Password)]
public string Pass { get; set; }
[Required]
public string LoginName { get; set; } // NickName/Email/MobilePhone
}
public class UserAccount_Register_ViewModel
{
public string NickName { get; set; }
public string Passw { get; set; }
public string PassConfirm { get; set; }
public string Email { get; set; }
public string MobilePhone { get; set; }
}
и вид:
@model GhafasehWebSite.Models.Account_Index_ViewModel
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<div class="AccountBook">
<div class="half-width">
@using (Html.BeginForm("Login", "Account"))
{
Html.EnableClientValidation();
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>ورود به سیستم</h4>
<hr />
@Html.ValidationSummary(true)
<div class="form-group col-md-12">
@Html.LabelFor(model => ((GhafasehWebAPI.Models.UserAccount_Login_ViewModel)(model.userAccount_Login_ViewModel)).LoginName, new { @class = "control-label col-md-4" })
<div class="col-md-8">
@Html.TextBoxFor(model => ((GhafasehWebAPI.Models.UserAccount_Login_ViewModel)(model.userAccount_Login_ViewModel)).LoginName, new { @class = "form-control", placeholder = "نام مستعار/ایمیل/شماره موبایل" })
@Html.ValidationMessageFor(model => ((GhafasehWebAPI.Models.UserAccount_Login_ViewModel)(model.userAccount_Login_ViewModel)).LoginName)
</div>
</div>
<div class="form-group col-md-12">
@Html.LabelFor(model => ((GhafasehWebAPI.Models.UserAccount_Login_ViewModel)(model.userAccount_Login_ViewModel)).Pass, new { @class = "control-label col-md-4" })
<div class="col-md-8">
@Html.TextBoxFor(model => ((GhafasehWebAPI.Models.UserAccount_Login_ViewModel)(model.userAccount_Login_ViewModel)).Pass, new { @class = "form-control" })
@Html.ValidationMessageFor(model => ((GhafasehWebAPI.Models.UserAccount_Login_ViewModel)(model.userAccount_Login_ViewModel)).Pass)
</div>
</div>
<div class="form-group">
<div class="col-md-offset-4 col-md-10">
<input type="submit" value="ورود" class="btn btn-primary" />
</div>
</div>
</div>
}
</div>
<div class="half-width">
@using (Html.BeginForm("Register","Account"))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>ثبت نام در سیستم</h4>
<hr />
@Html.ValidationSummary(true)
<div class="form-group col-md-12">
@Html.LabelFor(model => ((GhafasehWebAPI.Models.UserAccount_Register_ViewModel)model.userAccount_Register_ViewModel).NickName, new { @class = "control-label col-md-4" })
<div class=" col-md-8">
@Html.TextBoxFor(model => ((GhafasehWebAPI.Models.UserAccount_Register_ViewModel)model.userAccount_Register_ViewModel).NickName, new { @class = "form-control" })
@Html.ValidationMessageFor(model => ((GhafasehWebAPI.Models.UserAccount_Register_ViewModel)model.userAccount_Register_ViewModel).NickName)
</div>
</div>
<div class="form-group col-md-12">
@Html.LabelFor(model => ((GhafasehWebAPI.Models.UserAccount_Register_ViewModel)model.userAccount_Register_ViewModel).Passw, new { @class = "control-label col-md-4" })
<div class=" col-md-8">
@Html.TextBoxFor(model => ((GhafasehWebAPI.Models.UserAccount_Register_ViewModel)model.userAccount_Register_ViewModel).Passw, new { @class = "form-control" })
@Html.ValidationMessageFor(model => ((GhafasehWebAPI.Models.UserAccount_Register_ViewModel)model.userAccount_Register_ViewModel).Passw)
</div>
</div>
<div class="form-group col-md-12">
@Html.LabelFor(model => ((GhafasehWebAPI.Models.UserAccount_Register_ViewModel)model.userAccount_Register_ViewModel).PassConfirm, new { @class = "control-label col-md-4" })
<div class=" col-md-8">
@Html.TextBoxFor(model => ((GhafasehWebAPI.Models.UserAccount_Register_ViewModel)model.userAccount_Register_ViewModel).PassConfirm, new { @class = "form-control" })
@Html.ValidationMessageFor(model => ((GhafasehWebAPI.Models.UserAccount_Register_ViewModel)model.userAccount_Register_ViewModel).PassConfirm)
</div>
</div>
<div class="form-group col-md-12">
@Html.LabelFor(model => ((GhafasehWebAPI.Models.UserAccount_Register_ViewModel)model.userAccount_Register_ViewModel).Email, new { @class = "control-label col-md-4" })
<div class=" col-md-8">
@Html.TextBoxFor(model => ((GhafasehWebAPI.Models.UserAccount_Register_ViewModel)model.userAccount_Register_ViewModel).Email, new { @class = "form-control" })
@Html.ValidationMessageFor(model => ((GhafasehWebAPI.Models.UserAccount_Register_ViewModel)model.userAccount_Register_ViewModel).Email)
</div>
</div>
<div class="form-group col-md-12">
@Html.LabelFor(model => ((GhafasehWebAPI.Models.UserAccount_Register_ViewModel)model.userAccount_Register_ViewModel).MobilePhone, new { @class = "control-label col-md-4" })
<div class=" col-md-8">
@Html.TextBoxFor(model => ((GhafasehWebAPI.Models.UserAccount_Register_ViewModel)model.userAccount_Register_ViewModel).MobilePhone, new { @class = "form-control" })
@Html.ValidationMessageFor(model => ((GhafasehWebAPI.Models.UserAccount_Register_ViewModel)model.userAccount_Register_ViewModel).MobilePhone)
</div>
</div>
<div class="form-group">
<div class="col-md-offset-4 col-md-10">
<input type="submit" value="ثبت نام" class="btn btn-success" />
</div>
</div>
</div>
}
</div>
</div>
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
и контроллер:
[HttpGet]
public ActionResult Index()
{
return View(new Account_Index_ViewModel());
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Login(UserAccount_Login_ViewModel model)
{
if (ModelState.IsValid)
{
if (DataProvider.LoginUser(model, ModelState, Request, Session))
{
return RedirectToAction("Index", "Home");
}
}
return View("Index");
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Register(UserAccount_Register_ViewModel model)
{
if (ModelState.IsValid)
{
if (DataProvider.RegisterUser(model, ModelState, Request, Session))
{
return RedirectToAction("Index", "Home");
}
}
return View("Index");
}
вы должны знать, что проверка на стороне сервера работает нормально, но на стороне клиента спит. Итак, что вы предлагаете?
Любые ошибки javascript в консоли? Вы подтвердили, что ваши пучки загружаются должным образом? И ваша модель регистра не имеет DataAnnotations, поэтому проверки не было. – Brandon
@Brandon, вы, где правильно. мои пакеты не отображались правильно! БЛАГОДАРЮ. – ConductedClever