一、使用View Data首先要在Controller里加代码:public class ProductController : Controller{//// GET: /Product/public ActionResult Index(){ViewData["Messag......
一、使用View Data
首先要在Controller里加代码:
public class ProductController : Controller
{
//
// GET: /Product/
public ActionResult Index()
{
ViewData["Message"] = "Hello World";
return View();
}
}
然后在View里添加代码:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ToyStore.Models.Products>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Index
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Index</h2>
<%=ViewData["Message"] %>
</asp:Content>
内容就被传递了,但这样由于传入的值可能是任何类型的,所以你要自己做类型转换了,哈哈。
ViewData.Model是可以让你有个强类型的
ViewData.Model = _dataModel.ProductSet.ToList();
二、预防javascript注入攻击
默认是预防的,如果不想使用看下面的代码:
[ValidateInput(false)]
[AcceptVerbs(HttpVerbs.Post)]
1/4 1 2 3 4 下一页 尾页 |