asp.net - Required DataAnnotations needs BeginForm to fire validation in MVC5 -


is necessary write , place controls inside

@using (html.beginform())     {     // html elements , html helpers. } 

while using [required] dataannotations ?

i facing strange issue in mvc5 based application. problem have used 1 property named e.g "credit" in model , datatype of property integer , set[required] dataannotations above property.

but haven't used begin form. in case validation doesn't fire. whereas if write beginform validation works.

so, necessary place html elements & html helpers inside beginform validate controls ?

thanks
-nimesh.

if want client-side validation work, yes form controls etc. need within <form> tag (as generated html.beginform helper). server-side validation still work regardless of this.

like commenter above, question why want have controls outside form tag in first place. if plan submit data using ajax, it's better semantic design use form tag, because it's clear data items belong together, , makes easier gather data submit via ajax (e.g. if have jquery, can use $("#myform").serialize() automatically collect values controls within form , pass ajax request).


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -