Assign IENumerable<int> to a hiddenfor

Deadly 提交于 2021-02-11 06:11:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!