Featured post
asp.net - When `HttpGet` handling `Create` action method just returns `View()`, why doesn't the javascript validation get triggered on the browser? -
when httpget
handling create
action method returns view()
, causes form fields uninitialized.
why javascript validation not triggered when users views blank form?
i don't know inner workings, i'll give guess ;-)
first of all, has nothing whether or not [httpget]
or [httppost]
-- that's way works.
your average [httpget]
methods this:
[httpget] public actionresult index() { // data database return view(data); }
there aren't parameters in method, because want user hit controller when type in url (i.e. home/index
).
your usual [httppost]
method might this:
[httppost] public actionresult create(mymodel mymodel) { if (modelstate.isvalid) { // stuff } else { return view(mymodel); } }
i believe validation attributes aren't triggered until bind form values model , hit create(...) controller. if [httpget]
happened take in model parameter, validation triggered @ point well.
when return view existing, invalid model, somehow validationmessagefor(m => m.someproperty)
method knows validation property failed. that's part i'm not sure about.
by contrast, when return new view()
actionresult (as http get), brand-new, shiny model instantiated. creating new model simple creating poco (plain old c# object) -- validation not triggered.
as client-side validation, handled through javascript once click form's submit button. when [httpget]
request displays blank form, submit button hasn't yet been clicked (so javascript validation hasn't been started). in addition, believe once begin typing validation kicks in through various javascript events such change
, keydown
, keypress
, etc.
- Get link
- X
- Other Apps
Comments
Post a Comment