Concise MVC thought Framework--nancy (POST operation with external reference CSS and JS)

Source: Internet
Author: User

The previous introduction to the Nancy configuration and get base operation to come down to the post operation on Nancy.

The first step is to design the main interface, with the login interface as an example: login.cshtml

The path is:

After designing the page, set the pointing path and the related post operation in the previous modules class, as shown in:

<Body>    <DivID= "Login">        <formAction= " /Home"Method= "POST"ID= "Form1">            <DivID= "Bigimg">                <imgsrc= "Images/bigimg.jpg" />            </Div>            <DivID= "Loginbox">                <DivID= "Title-login">Login</Div>                <aID= "Title-register"href="#">Registered account ></a>                <DivID= "Forinput">Account Number:<BR>                    <P>                        <inputID= "User"name= "UserId"TabIndex= "1"type= "text">                        <spanID= "Error_userid"></span>                    </P>Password:<ahref="#"style= "color: #00A1D6; float:right; *margin-top: -10px; display:block;">Forgot my password?</a>                    <BR>                    <P>                        <inputID= "Password"type= "Password"TabIndex= "2"name= "Userpwd">                        <spanID= "Error_userpwd"></span>                    </P>Verification Code:<BR>                    <P>                        <inputID= "Code"name= "Verifity"TabIndex= "3"type= "text">                        <span>                            <imgID= "Verifity"onclick= "src = '/createcode? ' +math.random () "src= "/createcode"style= "Vertical-align:middle;">                        </span>                        <spanID= "Error_code"style= "MARGIN-LEFT:18PX;"></span>                    </P>                </Div>                    <inputtype= "Submit"ID= "Submit"value= "Login"onclick= "return Checklogin ()">            </Div>        </form>        </Div></Body>
View Code
1 #regionLogin--form verification, successfully jump to main page2 3post[" /Home"] = P = =4             {5                 //Get Form6                 varuser =Sqlhelperserver.todbvalue (request.form);7                 //Verify that the user name exists8                 if(!Userservice.isuserid (User.userid))9                 {Ten                     return "<script>alert (' User name does not exist! '); location.href= '/' </script>"; One                 } A                 //Verify password input is correct -                 if(Userservice.getuserpwd (user.userid)! =user.userpwd) -                 { the                     return "<script>alert (' Password wrong! '); location.href= '/' </script>"; -                 } -                 if(User.verifity! = session["Code"]. ToString ()) -                 { +                     return "<script>alert (' Verification code Error! '); location.href= '/' </script>"; -                 } +Viewbag.userid =User.userid; ADataTable dt =Userservice.getuser (); at                 returnview["user/home.cshtml", dt. Rows]; -             }; -  -             #endregion
View Code

Where about Sqlhelperserver is the public class for database operations, where Todbvalue is the form data that gets the page's incoming all HTML, where the label must have a "name" attribute.

 Public Static Object Todbvalue (Thisobject  value)        {            returnnull ?  DBNull.Value:value;        }
View Code

At this point, the post operation is complete!

It also involves referring to external JS and external CSS files, this common MVC is not the same, but also after quite a long study to find out, and finally found very simple, as long as the modules to create a new class, as follows:

 Public classBootstrapper:defaultnancybootstrapper {protected Override voidconfigureconventions (nancyconventions nancyconventions) {Base.            Configureconventions (nancyconventions);            NancyConventions.StaticContentsConventions.Clear (); NANCYCONVENTIONS.STATICCONTENTSCONVENTIONS.ADD (Staticcontentconventionbuilder.adddirectory ("CSS","/css")); NANCYCONVENTIONS.STATICCONTENTSCONVENTIONS.ADD (Staticcontentconventionbuilder.adddirectory ("JS","/script")); NANCYCONVENTIONS.STATICCONTENTSCONVENTIONS.ADD (Staticcontentconventionbuilder.adddirectory ("Images","/images")); }}
View Code

After that, we will explain the operation of the Verification Code acquisition and the session, as well as other similar to MVC, no much change.

Concise MVC thought Framework--nancy (POST operation with external reference CSS and JS)

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.