Case practice Diagram ASP. NET MVC Tutorial

Source: Internet
Author: User
Tags actionlink

Case practice Diagram ASP. NET MVC Tutorial
Text: World Qinggong First procedure: World Qinggong First


Chapter 0th Resources and editions
An ASP. NET MVC Resource link

ASP. NET MVC's official website
Http://www.asp.net/mvc/

W3cschool ASP. NET MVC Tutorial

Http://www.w3school.com.cn/aspnet/mvc_intro.asp


This article is currently completed project source download:

Http://pan.baidu.com/s/1jGf4dPs


Binary ASP. NET MVC version
RC 1 (January 09)
RC 2 (March 3, 09)
RTM (March 17, 09)

Chapter One introductory Example
A Hello ASP. NET MVC
Open VS2010, create a new project, such as; I don't remember having had the MVC installation behavior; MVC 2 should be VS2010.



Find the following in HomeController.cs,
......
Public ActionResult Index ()
{
viewdata["Message"] = "Hello MVC2!";


return View ();
}
......
Replace the original content with the current "Hello MVC2!";
Find the following in Site.master,
......
<div id= "title" >
</div>
......
Replace the original content with the "first MVC application"; then run, as;

This completes the Hello MVC 2 introductory example.


Two implementation of a login page
To implement a simple login page, do not connect the database first. Right-click the Models folder and add the new class Lylogin.cs;
Namespace Hellomvc2.models
{
public class Lylogin
{
public bool Login (string Username, string password)
{
if (username = = "Admin" && Password = = "1")
{
return true;
}
Else
{
return false;
}
}
}
}
Right-click the Controllers folder and add a new controller; All code is as follows;
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using SYSTEM.WEB.MVC;


Namespace Hellomvc2.controllers
{
public class Logincontroller:controller
{
//
GET:/login/


Public ActionResult Index ()
{
return View ();
}


[Acceptverbs (Httpverbs.post)]
public void Index (string username, string password)
{
Models.lylogin lyl = new HelloMvc2.Models.lylogin ();
if (Lyl.login (username, password))
{
Response.Write ("Login successful, user name is:" + username);
}
Else
{
Response.Write ("Login Failed");


}
}
}
}
Right-click on the Logincontroller Method index (), select Add view, select Master page, click Add, and automatically add the login folder under the Views folder. Automatically add the index.aspx file under it; in index.aspx add the following code;
<form action = "/login" method= "POST" >
<p> Username: <input type = "text" name = "username"/></p>
<p> Password: <input type = "password" name = "Password"/></p>
<p><input type = "submit" value = "Login"/></p>
</form>


Run directly, add login after the existing URL, the result is as follows;



Three more instances
1 Modify logon to title bar
Open Views-shared-site.master, the following third line of code is added;
......
<li><%: Html.ActionLink ("Home", "Index", "Home")%></li>
<li><%: Html.ActionLink ("about", "about", "Home")%></li>
<li><%: Html.ActionLink ("Login", "logon", "account")%></li>
......
Run, as a result;



2 Using the Controller
Right-click Controllers, add controller, name Userscontroller, tick the check box below, click Add;
Right click on Views, add folder users;
Right-click Users, add view, name index, use default values for parameters, and add another view, named details;


Open Views-shared-site.master and add the following line:
<li><%: Html.ActionLink ("User Management", "Index", "Users")%></li>


Open the users-index.aspx, and add it after the H2 tag pair:
<ul>
<li><a href= "Users/details/ndy22" > View user Details </a></li><br/>
<li><a href= "Users/create/ndy11" > Create new User </a></li>
</ul>


Open Details.aspx and add the following after the H2 tag pair:
<p>
<%= Html.encode (viewdata["Message"])%>
</p>


Open UsersController.cs, find the details method, and modify it as follows:
Public ActionResult Details (string id)
{
viewdata["Message"] = ID + "' s Details: ...";
return View ();
}
Run, as a result;











Case practice Diagram ASP. NET MVC Tutorial

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.