It wasn't long before I went out ,... So what's wrong or bad? I hope you can give me some advice... I also want to learn ..
I use mvc4 and ef6 .. So I generate models directly...
I will use a background verification to explain my development model...
Verify that the currently registered user name is available ..
..
This is a simple verification.
It's easy to understand ..
Use ajax to get the value of the text box
<Input type = "text" id = "txtname" onblur = "checkuser ()"/>
Onblur is executed when the text box loses focus
Function checkuser (){
VaR username = $ ("# txtname"). Val ();
$. Ajax ({
Type: "Post ",
Async: True,
URL: '@ URL. Content ("~ /Userview/GetUserName ")',
Data: {Username: username },
Success: function (data ){
If (Data! = 0 ){
Alert ("this user already exists ");
$ ("# Txtname"). Val ("");
}
}
});
}
The method name that points to the Controller .. The parameter is a string generated by var.
Next, the Controller
[Acceptverbs (httpverbs. Post)]
Public int GetUserName (string username)
{
Int userid = usermanageservice. getuserid (username );
Return userid> 0? 1: 0;
}
The username field in the database is queried based on the value of the text box .. Check whether the field ID exists
Determine the return value... Then 0 or 1 is returned.
If judgment ,,,
This is also a simple verification
In addition, the actionresult In the controller is of the bool type and then returns true or false for foreground verification,
I hope to help point out the unqualified items.
There is no preparation for the opening... Let me talk about my development model first.