asp.net mvc 4 - Validations in EditorForModel MVC4 -


i have dynamic view rendered partialview controller:

@model dynamic @using (html.beginform("edit", null,  formmethod.post))  {     @html.validationsummary(true)      @html.editorformodel()   <input type="submit" value="edit" /> } 

when hit submit button, should display validation message if missing or format not correct etc.,

however, on hitting submit button post edit action invoked before shows messages. typical postback in asp.net terms, happening. shouldn't show errors on client side before executing server controller code?

i bit confused, can clarify right way or doing wrong?

view

 @using (html.beginform("index", "content", formmethod.post, new { id = "frmindex" }))         {               <div>                 @if (model.id != 0)                 {                     <label style="float: left;">                         id</label>                     <input id="txtid-@model.id.tostring()" type="text" class="hide" value="@model.id.tostring()"/>                 }              </div>             <div>                               @if (model.name != null)                 {                     <label style="float: left;">                         name</label>                     <input id="txtname-@model.id.tostring()" type="text" class="hide" value="@model.name.tostring()"/>                 }                 else                 {                     <label style="float: left;">                         name</label>                     @html.textbox("name")                     @html.validationmessage("name")                 }             </div>  <input type="submit" value="save" style="float: left;" id="btnsave" title="btn" /> } 

use script validation

<script src="@url.content("~/script/jquery.validate.min.js")" type="text/javascript"></script> <script src="@url.content("~/script/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> 

script

 <script type="text/javascript">         $(document).ready(function () {              $("#btnsave").click(function () {                  var validation = $("#frmindex"); // id                 if (!validation.valid()) {                     return false;                 }              });         });     </script> 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -