MVC3 @Html.RadioButtonfor Pass data from view to controller

无人久伴 提交于 2019-12-02 01:42:36
Yasser

To, start with include a breakpoint in your view and check if the values are being passed or not.

Next, change your method signature from

 public void Question(string Email,QuestionClass.Tabelfields tf)

to

 public void Question(string email, QuestionClass.Tabelfields tf)

Also, I see you have used some strange syntax ( considering m also new to MVC ) where you could have simply used this

@Html.DisplayFor(modelItem => item.QuestionName)

instead of this

@Html.DisplayFor(modelItem => item.QuestionName,item)

and also, I have seen you profile, I know you are new to StackOverflow, so Welcome to StackOverflow ! you might want to read this & this as well. Cheers !

Update :

You are using this for displaying a radio button...

@Html.RadioButtonFor(modelItem =>item.SelectedOption, item.Option1, item)

what is item.Option1, I can see you have commented out Opion1,2,3,4. Or are you still using them ?

A very simple way of implementing this would be something like this

@Html.RadioButtonFor(modelItem =>item.SelectedOption, "Option1")
@Html.RadioButtonFor(modelItem =>item.SelectedOption, "Option2")
@Html.RadioButtonFor(modelItem =>item.SelectedOption, "Option3")

or you can also use,

@Html.RadioButtonFor(modelItem =>item.SelectedOption, item.Option1)
@Html.RadioButtonFor(modelItem =>item.SelectedOption, item.Option2)
@Html.RadioButtonFor(modelItem =>item.SelectedOption, item.Option3)

provided values exist in item.Option1/2/3/4 and are all of them are different.

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