PDA

View Full Version : مبتدی: مشکل در ایجاد validation در html helper



CodeforLife
دوشنبه 12 تیر 1396, 09:35 صبح
سلام به شما . من در برنامه Validation گذاشتم . که بعد از اینکه دکمه Submit زده میشه بررسی کنه ببینه گر خالی بود بگه باید فیلد رو وارد کنی....
ولی قبل از اینکه دکمه Submit زده بشه , در زمان اینکه صفحه بلافاصله لود میشه این متن Validation که فیلد خالی هست , نمایش داده میشه .... باید چه کار کنم ؟
کدها رو میگذارم اگر تونستید راهنماییم کنید .متشکرم






public class PersonAdmin
{
[Display(Name = "نام کاربری")]
[RegularExpression("^(09|989|9)(0[0-9]|1[0-9]|2[0-9]|3[0-9])[0-9]{7}$",
ErrorMessage = ApplicationRegisterKeys.IncorrectMobileNumberForma t)]
[Required(ErrorMessage = ApplicationRegisterKeys.FieldRequired)]
public string UserName { get; set; }//Mobile


[Display(Name = "کلمه عبور")]
[Required(ErrorMessage = ApplicationRegisterKeys.FieldRequired)]
[StringLength(50, ErrorMessage = ApplicationRegisterKeys.FieldLength)]
public string Password { get; set; }


[Display(Name = "تکرار کلمه عبور")]
[System.ComponentModel.DataAnnotations.Compare("Password", ErrorMessage = ApplicationRegisterKeys.VerifiedPassword)]
[StringLength(50, ErrorMessage = ApplicationRegisterKeys.FieldLength)]
public string VerifiedPassword { get; set; }
}




<body>
<div class="container">
@using (Html.BeginForm("GetVerificationCode", "Home", FormMethod.Post, new { @class = "form-signin" }))
{
<div class="text-center top-16">
<img id="profile-img" class="profile-img-card img-circle" src="//ssl.gstatic.com/accounts/ui/avatar_2x.png" style="width: 100px;" />
<h2 class="form-signin-heading">تغییر کلمه عبور</h2>
</div>
<div class="control-label">
<label class="control-label col-lg-4">نام کاربری</label>
<div class="col-lg-12">
@Html.TextBoxFor(x => x.UserName, new { @class = "form-control", placeholder = "شماره موبایل" })
@Html.ValidationMessageFor(x => x.UserName)
</div>
<div class="login-wrap">
<button class="btn btn-lg btn-login btn-block" type="submit" >ارسال کد تایید</button>
</div>
<p class="col-lg-4" id="invalidUsername" style="display:none;color:red">کاربری با این مشخصات در سیستم نمی باشد</p>
</div>
}
</div>
</body>



[HttpGet]
public ActionResult EntranceChangePassword(PersonAdmin personAdmin)
{
return View();
}

CodeforLife
دوشنبه 12 تیر 1396, 10:31 صبح
متوجه مشکلم شدم . من نباید در ورودی Action که Http post بود کلاس مدلم رو می فرستادم
[HttpGet]
public ActionResult EntranceChangePassword( )
{
return View();
}