c# - ASP.NET views and model, a small questions -


dears,

please me understand simple thing

i have model class:

public class vendorassistanceviewmodel {     public string name { get; set; }     public bool checked { get; set; } } public partial class csmodel : ientity {     public csmodel()     {          vendorassistances = new[]         {         new vendorassistanceviewmodel { name = "dj/band" },         new vendorassistanceviewmodel { name = "officiant" },         new vendorassistanceviewmodel { name = "florist" },         new vendorassistanceviewmodel { name = "photographer" },         new vendorassistanceviewmodel { name = "videographer" },         new vendorassistanceviewmodel { name = "transportation" },         }.tolist();     }       public ilist vendorassistances { get; set; } 

i have view:

@model ienumerable<csts.models.csmodel>   //some html code... 

i want know how show array of checkboxes model, using vendorassistances ? know simple, read lot of docs, still can not understand

thank you!

updated

i tried follow:

  1. into control in

             public override actionresult index(int pagenumber, int pagesize, string   nothing)   {    list<vendorassistanceviewmodel> vendorassistances = new[] { new vendorassistanceviewmodel { name = "dj/band" }, new vendorassistanceviewmodel { name = "officiant" }, new vendorassistanceviewmodel { name = "florist" }, new vendorassistanceviewmodel { name = "photographer" }, new vendorassistanceviewmodel { name = "videographer" }, new vendorassistanceviewmodel { name = "transportation" }, }.tolist(); 

i've added watch vendorassistances , insert breakpoint, , time tihs object null

why ?

you need iterate on model.vendorassistances , emit html code each vendorassistanceviewmodel.you can use code:

@foreach(var model in model) {     for(int i=0; < model .vendorassistances.count; i++)     {         @html.checkboxfor(x => model.vendorassistances[i].name)     } } 

also read this question can undedrerstand how post generated array action.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -