Reputation: 630
I'm having problem passing my model via an object link
Here is my model
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>
}
// the controller
[Authorize]
public ActionResult Add(UserItem item)
{
return RedirectToAction("Index");
}
here is what the url (action link) looks like, as you can see my embedded model object doesn't pass correctly
Add/0?Image=InventoryApp.Models.ItemImage&
Upvotes: 0
Views: 966
Reputation: 4413
The overload of ActionLink
that you're using is expecting a route value. Depending on what your action is expecting, something like this should work:
@Html.ActionLink("Add To Library", "Add", new { Url = item.Url })
This is assuming that your Add
action is expecting a string url.
On the other hand, if you're expecting to pass your entire model to the action, that isn't possible.
Upvotes: 1