Poll System in ASP.NET MVC -


i want display polling in section of page, have created these poco classes :

public class polls {     public int id { get; set; }     public string question { get; set; }     public bool active { get; set; }     public ilist<polloptions> polloptions { get; set; } }  public class polloptions {     public int id { get; set; }     public virtual polls polls { get; set; }     public string answer { get; set; }     public int votes { get; set; } } 

and have used below viewmodel :

public class pollviewmodel {     public int id { get; set; }     public string question { get; set; }     public string answer { get; set; } } 

then, passed model using above viewmodel view :

public actionresult index() {     var poll = p in db.polls                join po in db.polloptions on p.id equals po.polls.id                p.active == true                select new pollviewmodel {                     id=p.id,                    question=p.question,                    answer=po.answer     };      return view(model); } 

in view want display question , answer of poll, have tried code :

@section polling{     @foreach (var item in model.polls)     {         <input type="radio" /> @item.answer     } } 

above code works correctly want display question too, :

@section polling{     **@model.polls.question**     @foreach (var item in model.polls)     {         <input type="radio" /> @item.answer     } } 

how can that?

ps: have 1 row in polls table display in home page

there relationship between polls , pollsoption. polls db. , pass view. have pollsoptions connected to polls. no need join 2 tables.

controller

public actionresult index() {     // active polls     var poll = p in db.poll                p.active == true                select p;      // pass view     return view(poll); } 

view

@model ienumerable<polls>  @section polling{     @foreach (var question in model)     {         <h2>@question.question</h2>         @foreach(var answer in question.polloptions)         {             <input type="radio" /> @answer.answer         }     } } 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -