加拿大快乐8最快开奖
您好,欢迎来到源码搜藏!分享精神,快乐你我!提示:担心找不到本站?在百度搜索“源码搜藏”,网址永远?#27426;?#22833;! 
  • 首 页
  • VIP源码
  • 留言求助
  • MVC你可以轻松的阅读...
    ASP.NET MVC+EF框架+EasyUI实现
    ASP.NET MVC+EF框架+EasyUI实现
    ASP.NET MVC+EF框架+EasyUI实现
    ASP.NET MVC+EF框架+EasyUI实现
    ASP.NET MVC+EF框架+EasyUI实现
    ASP.NET MVC+EF框架+EasyUI实现
    ASP.NET MVC+EF框架+EasyUI实现
    ASP.NET MVC+EF框架+EasyUI实现
    ASP.NET MVC+EF框架+EasyUI实现
    ASP.NET MVC+EF框架+EasyUI实现
    ASP.NET MVC3数据绑定到VIEW的方式

    1、     指定页面数据的强类型Module

    数据类型是强类型,编译时报错,运行效?#30690;?/span>

    Action:

          public ActionResult Index()

          {

            var _instructors = new List<Instructor>(

               new Instructor[]

               {

                  new Instructor

                  {

                     Name = "Nimane1",

                     TwitterHandler = "@fasdd",

                     HtmlDescription = "This"

                  }

                  , new Instructor

                  {

                     Name = "Nimane2",

                     TwitterHandler = "@fasdd",

                     HtmlDescription = "This"

                  }

               }

            );

            ViewBag.Message = "Welcome to ASP.NET MVC!";

            return this.View(_instructors);

          }

    View:

    @using MvcApplication1.Models

    @model IEnumerable<Instructor>

    @{

        ViewBag.Title = "Index";

        Layout = "~/Views/Shared/_Layout.cshtml";

    }

    <h2>@ViewBag.Message</h2>

    <div>

        @foreach (var item in Model)

        {

            @Html.Partial("InstructorView", item)

        }

    </div>

    InstructorView:

    @model MvcApplication1.Models.Instructor

    <fieldset>

        <legend>Instructor</legend>

        <div class="display-label">

            Name</div>

        <div class="display-field">

            @Model.Name

        </div>

        <div class="display-label">

            TwitterHandler</div>

        <div class="display-field">

            @Model.TwitterHandler

        </div>

        <div class="display-label">

            HtmlDescription</div>

        <div class="display-field">

            @Html.Raw(@Model.HtmlDescription)</div>

    </fieldset>

    <p>

        @Html.ActionLink("Edit", "Edit", new { })

        @Html.ActionLink("Back to list", "Index")

    </p>

    2、     使用ViewData绑定到页面

    数据类型是object,运行时报错,在 页面中需要对数据进行显示转换,运行效?#23454;?/span>

    Action:

          public ActionResult ViewData ()

          {

            List<string> colors = new List<string>(

               new string[]

               {

                  "red","green","blue"

               }

            );

     

            ViewData["listColors"] = colors;

            ViewData["dateNow"] = DateTime.Now;

            ViewData["name"] = "Nicoles";

            ViewData["age"] = 24;

     

            return this.View();

          }

    View:

        <div>

            <p>section for viewdata display:</p>

            <p>my name is :

                <b>@ViewData["name"]</b>

                <b>@ViewData["age"]</b> years old.

                <br/>

                I like the colors:

            </p>

            <ul id="colors">

                @foreach (var color in ViewData["listColors"] as List<string>)

                {

                    <li>

                        <font color="@color">@color</font>

                    </li>

                }

                <li></li>

            </ul>

        </div>

    3、     使用ViewBag绑定到页面

    数据类型是dynamic,运行时报错,运行效?#25163;?/span>

          public ActionResult ViewBag()

          {

            List<string> colors = new List<string>(

               new string[]

               {

                  "red","green","blue"

               }

            );

            ViewBag.ListColors = colors;

            ViewBag.DateNow = DateTime.Now;

            ViewBag.Name = "Nicoles";

            ViewBag.Age = 24;

            return this.View();

          }

    View:

    <div>

            <p>section for viewbag display:</p>

            <p>my name is :

                <b>@ViewBag.Name</b>

                <b>@ViewBag.Age</b> years old.

                <br/>

                I like the colors:

            </p>

            <ul id="colors_a">

                @foreach (var color in @ViewBag.ListColors)

                {

                    <li>

                        <font color="@color">@color</font>

                    </li>

                }

                <li></li>

            </ul>

        </div>

    标签:源码搜藏 蔓蔓视频 爱看电影网

    加拿大快乐8最快开奖