How use unobtrusive validation without a model

Posted by Ross Cyrus on Stack Overflow See other posts from Stack Overflow or by Ross Cyrus
Published on 2012-03-21T09:58:24Z Indexed on 2012/03/21 11:29 UTC
Read the original article Hit count: 228

i have simple a form wich made by htmlHelper(mvc3) then inside of it i have 2 input field 1:type=text 2:type=submit to submit the form. there is no model behind.so i need to perfom a clientside validation on the textfield before submit it to the server.but i dont know how. i tried this puting manualy the 'data-* artibute , but does not work :

@using( Html.BeginForm())
{
      <label for="UserName" >User Name</label>
      <div class="editor-field">
      <input type="text" data-val="true" data-val-requierd="You must  provide an user Name" id="userName" name="userName" placeholder="Enter Your User Name" />
      </div>
      <input type="submit" value="Recover" />
}

the "jquery.validate.min.js" and jquery.validate.unobtrusive.min.js and jquery.validate.min.js

and jquery.validate.unobtrusive.min.js are loaded to the page.


It doesnt let me to answer my self ,so i put it here : I solve it my self,just made an other view wich has its own model and Required on its propertyis and then just copy the renderd html to my own,and i got this and works :

<input data-val="true" data-val-required="You must  provide an user Name" id="UserName" name="UserName" type="text" value=""  placeholder="Enter your User Name"/>
    <span class="field-validation-valid" data-valmsg-for="UserName" data-valmsg-replace="true"></span>

And there is no type="Required".any way thank you guys.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about unobtrusive-validation