Let's use an example to describe how to submit the MVC form and receive parameters and perform the operations on the LINQ data.
1. Create a View File
The following is the content of the View File:
<% @ Page title = "" Language = "C #" masterpagefile = "~ /Views/shared/site. master "inherits =" system. web. MVC. viewpage <bxhlcms. models. cms_admint> "%> </P> <p> <asp: content ID = "content1" contentplaceholderid = "titlecontent" runat = "server"> <br/> adminlogin <br/> </ASP: content> </P> <p> <asp: content ID = "content2" contentplaceholderid = "maincontent" runat = "server"> </P> <p> <H2> system background management logon </H2> <br/> <br/> <% using (HTML. beginform ("adminlogin", "manage") <br/>{%> <br/> <% = html. validationsummary (true, "Logon Failed. Please enter your username and password correctly ") %> <br/> <div> <br/> <fieldset> <br/> <legend> Administrator Logon </legend> </P> <p> <Div class = "editor-label"> <br/> User Name: <br/> </div> <br/> <Div class = "editor-field"> <br/> <input id = "username" name = "username" type = "text"/> <br/> </div> </P> <p> <Div class = "editor-label"> <br/> password: <br/> </div> <br/> <Div class = "editor-field"> <br/> <input id = "password" name = "password" type = "password"/> <br/> </div> </P> <p> <br/> <input type = "Submit" value = "login" /> <br/> </P> <br/> </fieldset> <br/> </div> <br/> <% }%> </P> <p> </ASP: content>
1. Pay attention to the reference of object classes in the file header.
2. Use HTML. beginform to submit the form.
3. The other content is the same as the ASP and PHP format we used previously. Note that the label names of submitted data such as text boxes should not be messy, because they will be used later in action.
Ii. Action page
[Httppost] // submit in post Mode
Public actionresult adminlogin (string username, string password) // The parameter must correspond to the submitted parameter.
{
Usersmodelsdatacontext umdc = new usersmodelsdatacontext (); // instantiate the LINQ class and use the LINQ program.
VaR query = from V in umdc. cms_admint where v. Name = username select V;
If (query. Count ()> 0)
{
Return redirecttoaction ("Index", "home ");
}
Else
{
Return redirecttoaction ("adminlogin", "manage ");
}
}
Previous Article: Entities automatically generated by using LINQ in ASP. net mvc five models