Using a base MVC - front and rear ends to exchange data

1 acquisition parameters

Request.Form: acquiring data (received data to Form submission) POST method submitted; var data = Request.Form [ "data"];

Request.QueryString: obtaining address parameters field (the data submission GET) var data = Request.QueryString [ "data"];

Page 2 Jump

public actionResult Index

{
return viewn () - Returns the default view Index.cshtml
return View ( "PayList") - call PayList.cshtml Index Notes from the controller: here is call the view, not after PayList controller, if the controller logic code is not on a call
return Redirct ( "Pay / PayList"); - Jump only (no overload) the path through url
return RedirctToAction ( "PayList") - call PayList the controller from the Index controller, and finally return PayList.cshtml view
}
 
public actionResult PayList
{
return View (); - return to the default view view PayList.cshtml
}
 
3 used to upload data to the front end of the background (the ViewData and the ViewBag)
 
E.g:

public ActionResult Index()
{
List<string>colors = new List<string>();
colors.Add("red");
colors.Add("green");
colors.Add("blue");
ViewBag.ListColors = colors; //colors is List
ViewBag.DateNow= DateTime.Now;
ViewBag.Name= "hejingyuan";
ViewBag.Age = 25;
return View();
}

View


<p>
My name is <b>@ViewBag.Name</b>, <b>@ViewBag.Age</b> years old.
<br />
I like the following colors:
</p>
<ul id="colors">
@foreach (var color in ViewBag.ListColors)
{
<li><font color="@color">@color</font> </li>
}
</ul>
<p>
@ViewBag.DateNow
</p>


4 base.TempData [ ""] to save all the controllers can be used in the session, but used once inside, they emptied

 

 
 
 
 
 

Guess you like

Origin www.cnblogs.com/yyl001/p/10286095.html