ASP.NET MVC framework 学习

http://www.cnblogs.com/lmfeng/archive/2013/03/28/2986123.html  MVC数据绑定方式

http://www.cnblogs.com/lmfeng/archive/2013/03/28/2986364.html  MVC布局方式

http://www.cnblogs.com/willick/p/3224144.html#header_1       Razor语法

 

 

 

<div class="section">

    @{int i = 1;}

    @foreach (var CourseSection in @Model.CourseSection)

    {

        <a sectionid="@CourseSection.SectionId" filepath="@CourseSection.FilePath"><em>@(i > 9 ? i.ToString() : "0" + i.ToString())</em>@CourseSection.Title</a>

        i++;

    }

 </div>

 

 

 

    @Html.TextBox("testsn", 1, new {id="idtest",Class="fsadf",avalu="555555555"});

@Html.TextBox("txttest", "文本值", new { id = "idtxttest", @class = "fsadf", avalu = "5555" });

 

 

 

                    @for (int i = 0; i < sl.Count; i++)

                    {

                        if (sl[i].Status)

                        {

                            <label class="check-label" for="@string.Format("ckb{0}", i)"><input type="checkbox" id="@string.Format("ckb{0}", i)" name="service" value="@sl[i].ServiceId" checked="checked"><b class="@sl[i].Ico"></b><em>@sl[i].ServiceName</em></label>

                        }

                        else

                        {

                            <label class="check-label" for="@string.Format("ckb{0}", i)"><input type="checkbox" id="@string.Format("ckb{0}", i)" name="service" value="@sl[i].ServiceId"><b class="@sl[i].Ico"></b><em>@sl[i].ServiceName</em></label>

                        }

                    }

 

           @if (id > 0 && coverlist.Count > 0)

                {

                    var i = 0;

                    foreach (var p in coverlist) {

                        i++;

                        <div class="p-img"><div class="up-image"><input type="hidden" value="@p.FileId" name="Photo"><div style="text-align:center;"><img src="@this.Url.ResourcePublishUrl(p.FileId)" /></div><span class="clearfix"><i class="p-id">@string.Format("0{0}", i)</i><i class="im-right"><b></b></i><i class="im-left"><b></b></i></span><a class="im-x"><b></b></a></div></div>

                    }

                }

 

 

1 MVC布局设置

新的Layout布局系统

要点:

A.Layout属性:等同于原来的MasterPageFile属性.

B.@RenderBody()方法:直接渲染整个View到占位符处,而不需要原来所使用的<asp:Content />.

C.@RenderPage()方法:渲染指定的页面到占位符处.

D.@RenderSection方法:声明一个占位符,和原来的<asp:ContentPlaceHolder />功能类似.

E.@section标记:对@RenderSection方法声明的占位符进行实现,和原来的<asp:Content />功能类似.

 

@{

    ViewBag.Title = "Index";

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

}

 

1.@RenderBody() 方法的使用  每个布局页必须

 

 2 开始渲染其他页2<br />
        @RenderPage("~/Views/Home/ViewPage1.cshtml")
   渲染其他页结束2<br />

 

3.@RenderSection方法和@section标记

布局页面设置

    第一种方式

    @RenderSection("SectionA", false)

 

    第二种方式

    @{

        if (IsSectionDefined("SectionB"))

        { @RenderSection("SectionB")

        }

    }

对应视图页面

@section SectionA{

    <div>这里是SectionA:也不需要写神马runat="server"啊,有木有</div>

}

 

@section SectionB{

    <div>这里是SectionB:也不需要写神马&lt;asp:Content /&gt啊,有木有</div>

}

posted @ 2014-04-03 19:36  dapeng888  阅读(190)  评论(0编辑  收藏  举报