Tuesday, 15 March 2011

asp.net mvc - Validation stopped working on use of formmethod.post -



asp.net mvc - Validation stopped working on use of formmethod.post -

i trying post external url eg. (www.msn.com) on press of submit button.but when none of valdation works...it create entry without info in external url 2. not going controller when press submit button. don't know if doing wrong...

here code view:

@model n.models.popupdemomodel <script src="@url.content("~/scripts/jquery.validate.min.js")" type="text/javascript"></script> <script src="@url.content("~/scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> @using (html.beginform("demo","home", formmethod.post, new { @action = "https://www.msn.com?encoding=utf-8/post" })) { @html.validationsummary(true) <fieldset> <input type=hidden name="oid" value=""> <input type=hidden name="returl" value = "test" /> <input type="hidden" name="debug" value=1 /> <input type="hidden" name="debugemail" value = "a@test.com" /> <div class="editor-label grid_2"> @html.labelfor(model => model.first_name) </div> <div class="editor-field grid_3"> @html.textboxfor(model => model.first_name, new { @class = "demo-field-longer" }) </div> <div class="grid_3 error long" style="margin-left:250px"> @html.validationmessagefor(model => model.first_name) </div> <div class="clear"></div> <div class="editor-label grid_2"> @html.labelfor(model => model.email) </div> <div class="editor-field grid_3"> @html.textboxfor(model => model.email, new { @class = "demo-field-longer" }) </div> <div class="grid_3 error long" style="margin-left:250px"> @html.validationmessagefor(model => model.email) </div> <div class="clear"></div> <div class="editor-label grid_2"> @html.labelfor(model => model.phone) </div> <div class="editor-field grid_3"> @html.textboxfor(model => model.phone, new { @class = "demo-field-longer" }) </div> <div class="grid_3 error long" style="margin-left:250px"> @html.validationmessagefor(model => model.phone) </div> <div class="clear"></div> <div class="editor-label grid_2"> @html.labelfor(model => model.company) </div> <div class="editor-field grid_3"> @html.textboxfor(model => model.company, new { @class = "demo-field-longer" }) </div> <div class="grid_3 error long" style="margin-left:250px"> @html.validationmessagefor(model => model.company) </div> <div class="clear"></div> <div class="clear"></div> <div class="grid_2 sub-spacer">&nbsp;</div> <div class="editor-field grid_2 submit"> <input type="submit" value="submit" id="demo-submit-button"/><br /> @viewdata["demomessage"] </div> </fieldset>

here model:

public class popupdemomodel { [required] [email] [displayname("email address")] public string email { get; set; } [required] [displayname("phone number")] public string phone { get; set; } [required] [displayname("contact name")] public string first_name { get; set; } [required] [displayname("company name")] public string company { get; set; } public string messagesent { { homecoming "we'll contact shortly."; } } }

it's doing told to.

the html <form> tag sends post request url in action attribute.

html.beginform() creates <form> tag action attribute points controller.

when set action attribute explicitly, replace value mvc , create go straight url.

asp.net-mvc razor

No comments:

Post a Comment