0
我有通過對象鏈接Asp.net MVC3傳遞一個動作鏈接模型中的模型
這裏路過我的模型的問題是我的模型
public class ItemImage
{
[Required,Key,DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[DataType(DataType.ImageUrl)]
public string Url { get; set; }
[Required]
public int Width { get; set; }
[Required]
public int Height { get; set; }
}
public class UserItem
{
public UserItem()
{
Image = new ItemImage();
Private = true;
}
#region
[Required, Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }
[Required]
public string EAN { get; set; }
[Required]
public string Title { get; set; }
[Required]
[DataType(DataType.Date)]
public DateTime AddDate { get; set; }
[Required]
[DataType(DataType.Date)]
public DateTime PublishDate { get; set; }
[Required]
public string Publisher { get; set; }
[Required]
public string Binding { get; set; }
[EnumDataType(typeof(ItemType))]
public ItemType Type { get; set; }
[EnumDataType(typeof(ItemStatus))]
public ItemStatus Status { get; set; }
[Required]
public ItemImage Image { get; set; }
[Required]
public int Quantity { get; set; }
[Required]
public bool Private { get; set; }
#endregion
} // other properties
}
// the view code
@foreach (InventoryApp.Models.UserItem item in Model)
{
<tr>
<td>
@Html.ActionLink("Add To Library", "Add",item)
</td>
</tr>
}
//控制器
[Authorize]
public ActionResult Add(UserItem item)
{
return RedirectToAction("Index");
}
這裏是url(動作鏈接)的樣子,你可以看到我的嵌入式模型對象沒有正確傳遞
Add/0?Image=InventoryApp.Models.ItemImage&
嗯結束了分解和傳遞只有導入屬性我需要在他們的服務器端重新創建我的模型對象,並將其添加到數據庫。 – nagates 2012-01-05 16:17:48