Attribution: Song等
I first write a blog, if there is any wrong place, please point out, also hope that many forgive me, or there are more simple methods, hope the great God, thank you!
Form
@using (Html.BeginForm ("Stockitemsins", "Stockitems", FormMethod.Post, new {id = "search"}))
{
<input class= "Input-small" type= "text" style= "width:283px" id= "Stock_name" name= "Stock_name" value= "@Model. STOCK_ NAME "/>
Properties of text boxes
<input type= "button" id= "Submit" value= "OK" class= "btn btn-primary"/>
}
var Model = {}; Define a variable
Model.stock_name = $ (' #STOCK_NAME '). Val (); Get the value of a text box
$.ajax ({
Type: "POST",//Submission method
URL: "@Url. Action (" Checkstock ")",//Submit Path
Data: {
"Stock_name": model.stock_name,//Submit data
},//data, which is used in JSON format for transmission
Success:function (Result) {//Return data is processed according to the result; Get background data processing result
if (result = = "0") {//Determine if the returned data meets the criteria
$ (' #search '). Submit (); Submit data if eligible
Alert ("Data submitted successfully!") "); Pop-up window tips
}
else {
Alert ("This XX already exists!") "); Does not meet the criteria
}
}//Data processing in the background it's not written.
});
JSON determines whether the value of the text box already exists in the database