JS validation form data legitimacy code
$(function () { $("#btnApplication"). Click (function () { varImageUrl = $ ("#SXtPhoto"). Val (); vardesc = $ ("#tDesc"). Val (); varType = $ ("#type"). Val (); if(ImageUrl = = "") {alert ("Please upload photos!" "); return; } if(desc = = "") {alert ("Please fill in the reasons for your recommendation!" "); return; } if(Type = = 0) {alert ("Please choose the talent type!" "); return; } $( This). attr ("Disabled", "disabled"); //$ ("Form:last"). Submit ();$(". MyForm "). Submit ();//Submit Form }); });
MVC View Code
<H1>Online Application</H1>@using (Html.BeginForm ("Apply", "Star", FormMethod.Post, new {@class = "MyForm"})) {<Divclass= "Application_b_3"> <Tablewidth= "820"Border= "0"> <TR> <TDwidth= "a"Height= " the">Talent Type</TD> <TDwidth= "730">@Html. dropdownlistfor (M = M.starmodel.typeid, model.droplist, new {id = "type", @clas s = "my-"})</TD> </TR> <TR> <TDHeight= " the">Home Talent Photo</TD> <TD> <Divclass= "Picture_an"ID= "Uploadphoto"style= "width:142px"> <ahref= "javascript:void (0);"class= "Btn_addpic"><span><em>+</em>Uploading photos</span> <inputTabIndex= "3"title= "Support jpg, JPEG, GIF, PNG format, file less than 5M"size= "3"name= "Pic"ID= "Absfileinput"class= "Fileprew"type= "File" /> </a> </Div> </TD> </TR> <TR> <TDHeight= " the"></TD> <TD>@Html. hiddenfor (M = M.starmodel.usergravatar, new {id = "Sxtphoto"}) <imgsrc=""ID= "Imgphoto"Height= "176px" /> </TD> </TR> <TR> <TDHeight= "+">Reasons for Recommendation</TD> <TD>@Html. textareafor (M = M.starmodel.applyreason, new {id = "Tdesc"}) </TD> </TR> <TR> <TDHeight= " the"></TD> <TD> <ahref= "javascript:void (0)"ID= "Btnapplication"><imgsrc= "@Url. Content ("~/areas/sns/themes/default/content/images/ap_9.gif ")" Alt="" /></a> </TD> </TR> </Table> </Div> }
MVC Controller Code
The first form of a notation
[HttpPost] Public ActionResult Apply (ViewModel.SNS.Star model) {// logic }
The second type of notation
[HttpPost] Public actionresult Apply (formcollection Form) {// logic }
MVC uses Html.BeginForm to submit a form code explanation