学习: ASP.NET MVC开发入门-UI实现根据查询条件返回Model层的查询结果

UI端显示Mode层的数据时,可选择在view创建时勾选'Create a strongly-typed view',

这样工具自动生成<%%>代码,省去了些敲UI代码的工作。

 

在 'View data Class' / '中选择Model类中返回Entity实例的名称。

在'View content (empty, create delete, details, empty, list)'中选择了Details,

用来根据查询条件返回的某一条具体的Entity实例。

 

点击确定后,UI生成如下代码:

 

ExpandedBlockStart.gif View Code
< html  xmlns ="http://www.w3.org/1999/xhtml"   >
< head  id ="Head1"  runat ="server" >
     < title >AnnounceDetails </ title >
</ head >
< body >
     < h2 >AnnounceDetails </ h2 >

     < fieldset >
         < legend >Fields </ legend >
        
         < div  class ="display-label" >ID </ div >
         < div  class ="display-field" > <% : Model.ID  %> </ div >
        
         < div  class ="display-label" >Title </ div >
         < div  class ="display-field" > <% : Model.Title  %> </ div >
        
         < div  class ="display-label" >Content </ div >
         < div  class ="display-field" > <% : Model.Content  %> </ div >
        
         < div  class ="display-label" >Category </ div >
         < div  class ="display-field" > <% : Model.Category  %> </ div >
        
     </ fieldset >
     < p >
         <% : Html.ActionLink( " Edit " " Edit " new  {  /*  id = Model.PrimaryKey  */  })  %> |
         <% : Html.ActionLink( " Back to List " " Index " %>
     </ p >
</ body >
</ html >

 

接下来在UI对应的controller中添加对应的Action如 ActionResult AnnounceDetails()

在该action中,将Model层返回的实例添加View()中

 

ExpandedBlockStart.gif View Code
  public ActionResult AnnounceDetails()
        {
            IAnnounceInfo announceInfo =  new MockAnnounceService();
             var announceDetail = announceInfo.GetDetails( 1);
             return View(announceDetail);
        }

 

添加后,点击F5, 查看结果,看到UI正常显示,并返回某一个特定ID的Entity

 

转载于:https://www.cnblogs.com/myroad/archive/2012/10/21/2733071.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值