ASP. net mvc 6 models uses the object class automatically generated by LINQ-(submit a form)

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.