首页 > 新闻

Asp.Net MVC 之 View

时间:2009-04-20 09:39:48  作者:ITbird  我要投稿
Linux初探欢迎您的投稿,投放方法请点击这里查看,我们会定期赠送精美小礼品给优秀的投稿作者。海纳百川 取则行远!LinuxGoo欢迎您的到来。
一、使用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)]  


如果您需转载 Asp.Net MVC 之 View,请注明来自LinuxGoo.com,其版权归原作者所有。请广大网友留言时遵纪守法,使用文明用语。如果您在应用中有什么问题,请在下面留言,我们会尽快解答。
来顶一下
近回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
相关文章
栏目热门