I'm just venturing out into the world of MVC (v4) and I'm having real trouble getting the actual selected values of a list of radiobutton lists. I'll post everything that I've done so far in the hope that someone more intelligent than I could point me in the right direction:
Here's my content structure:
My Model
namespace ICASolution.Models
{
public class MultipleChoiceViewModel
{
public int iQuestionID { get; set; }
public string zQuestionTitle { get; set; }
public string zQuestionText { get; set; }
public List<Answers> lAnswers { get; set; }
}
public class Answers
{
public int iAnswerID { get; set; }
public string zAnswerText { get; set; }
public bool bCorrect { get; set; }
public string selectedAnswer { get; set; }
}
}
My surface controller:
namespace ICASolution.Controllers
{
public class MultipleChoiceSurfaceController : SurfaceController
{
//
// GET: /MultipleChoiceSurface/
//public ActionResult Index()
//{
// return PartialView("MultipleChoice", new MultipleChoiceViewModel());
//}
[HttpPost]
public ActionResult Grade(MultipleChoiceViewModel model)
{
return RedirectToCurrentUmbracoPage();
}
public ActionResult Index()
{
var TestPage = Umbraco.Content(CurrentPage.Id);
var questions = new List<MultipleChoiceViewModel>();
foreach (var child in TestPage.Children)
{
var questionid = child.Id;
var questiontitle = child.GetPropertyValue("questionTitle");
var questiontext = child.GetPropertyValue("questionText");
questions.Add(new MultipleChoiceViewModel { iQuestionID = questionid, zQuestionTitle = questiontitle, zQuestionText = questiontext, lAnswers = answerList(questionid) });
}
return PartialView("MultipleChoice", questions);
}
public List<Answers> answerList(int iMyQuestionID)
{
var questionPage = Umbraco.Content(iMyQuestionID);
var answers = new List<Answers>();
foreach(var child in questionPage.Children)
{
answers.Add(new Answers { iAnswerID = child.Id, zAnswerText = child.GetPropertyValue("answerTitle"), bCorrect = child.GetPropertyValue("correctAnswer") });
}
return answers;
}
}
}
Getting values of Radio Button on HttpPost
Hi folks,
I'm just venturing out into the world of MVC (v4) and I'm having real trouble getting the actual selected values of a list of radiobutton lists. I'll post everything that I've done so far in the hope that someone more intelligent than I could point me in the right direction:
Here's my content structure:
My Model
My surface controller:
and finally my partial:
Everything renders fine when displayed to the user:
But I just can't work out how to get the selections that the user has made.
Any help would be greatly appreciated.
Thanks, Craig
when sending over with the model as you do, you should have access to .SelectedValue and SelectedText. These should fit what you need
Nah, the models completely empty
Hello Im in the same situation, do you find the solution??
is working on a reply...