3
Reply

Asp.net MVC model through validation of html page

Dr.Ajay Kashyap

Dr.Ajay Kashyap

Jun 2 2016 6:38 AM
279
I have a question on MVC ?
I created Model and also create html page using HTML tag Now I want to validate that page using That Model ...?
so how to validate html page (simple html tag )using model in mvc ?
 
 Model:-
public partial class contactu
{
public int Id { get; set; }
[Required(ErrorMessage = "please provide First Name", AllowEmptyStrings = false)]
[AllowHtml]
public string Name { get; set; }
public string Address { get; set; }
[DataType(DataType.EmailAddress)]
[Required(ErrorMessage = "Please enter correct email address")]
public string Email { get; set; }
public string PhoneNo { get; set; }
public string Subject { get; set; }
public string Msg { get; set; }
}
 
Html Page :-
<form method="post" class="form-style-9" action="@Url.Action("contactus", "AdminUserLogin")">
<ul>
<li>
@*<input type="text" name="Name" class="field-style field-split align-left" placeholder="Name", id="Name" />*@
<input type="email" name="Email" class="field-style field-split align-right" placeholder="Email" id="Email" />
</li>
<li>
<input type="text" name="Phone" class="field-style field-split align-left" placeholder="Phone" id="Phone"/>
<input type="text" name="Address" class="field-style field-split align-right" placeholder="Address" id="Address"/>
</li>
<li>
<input type="text" name="Subject" class="field-style field-full align-none" placeholder="Subject" id="Subject"/>
</li>
<li>
<textarea name="Message" class="field-style" placeholder="Message" id="Message"></textarea>
</li>
<li>
<input type="submit" value="Send Message" />
</li>
</ul>
</form>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
 

Answers (3)