问题
I am working with a project where in I have a veiwmodel
[Required(ErrorMessage = "Enter Title")]
[Display(Name="Title")]
public string Title { get; set; }
[Required(ErrorMessage = "Enter Description")]
[Display(Name="Description")]
public string Description { get; set; }
[Required(ErrorMessage = "Select Site")]
[Display(Name = "Site")]
public string Site { get; set; }
[Required(ErrorMessage = "Upload File is required")]
[Display(Name = "Upload File")]
[ValidatePlanFile]
public HttpPostedFileBase File { get; set; }
public int SelectedUser { get; set; }
public List<Guid> Users { get; set; }
I need to assign the Users property to a hiddenfor.
Would it be possible to assign IENumerable to a view?
回答1:
It is as usual how we do with @Html.TextBoxFor
or others.
@model IEnumerable<Type>
@foreach(var item in Model)
{
@Html.HiddenFor(model => item)
}
来源:https://stackoverflow.com/questions/22497346/assign-ienumerableint-to-a-hiddenfor