随笔 - 290  文章 - 10  评论 - 85  2

1. html helper 可以缩写代码的,下面2段代码是相同效果

@Html.DropDownList("TourList")
 <select name="aaa">
                    
                     @foreach (SelectListItem item in ViewBag.TourList)
                     {
                         var selected = "";
                         if (item.Selected)
                         {
                             selected = "selected='selected'";
                         }
                           <option value="@item.Value" @selected>@item.Text</option>
                     }
                      </select>

2. 用form提交的entity.id, entity.name 可以组装成controller的方法的entity类参数,

但是对象或者集合做参数,mvc好像是不能自动组装的. 例如下面的Tour字段和FromCity,BackCity字段

    public class TourInstance: Entity
    {
        public virtual string Code { get; set; }
        public virtual Tour Tour { get; set; }
        public virtual IList<City> FromCity { get; set; } //出发城市
        public virtual IList<City> BackCity { get; set; } //返回城市
        public virtual DateTime StartDate { get; set; }
        public virtual DateTime EndDate { get; set; }
        public virtual int Capacity { get; set; } 
        public virtual bool IsActive { get; set; } 
    }

 

 

posted on 2013-07-22 02:53  Gu  阅读(...)  评论(...编辑  收藏