Hi, I'm having some trouble posting data to a surface controller. I have the following model:
public class QuestionAndAnswerModel
{
public string Answer { get; set; }
public string Question { get; set; }
}
And I have a Post method in my surface controller as follows:
public ActionResult PostAnswers(IList<QuestionAndAnswerModel> questionAndAnswers)
{
....
}
Now its almost working, I know the method gets called as I can hit breakpoints in the method, but my problem is, the questionsAndAnswers parameter is always null. I've checked Request.Form and it is populated with the data I have submitted. I've tried a few different types for the parameter (IEnumerable, IList) but that doesn't make any difference. So I'm wondering if my input fields are set up correctly.. Currently they are in the following format:
The naming convention of each element is based off what I have found referenced here for standard controllers. I'm just wondering if anyone knows why my form values aren't coming through correctly? Hopefully its really obvious! Thanks
Finally figured this out! Basically, because I was using question numbers starting from 1, I also passed that in as the @index for the inputs on the page. This number needs to start at 0 otherwise it seems asp.net doesn't work out that it is a list.
Post data to surface controller
Hi, I'm having some trouble posting data to a surface controller. I have the following model:
And I have a Post method in my surface controller as follows:
Now its almost working, I know the method gets called as I can hit breakpoints in the method, but my problem is, the questionsAndAnswers parameter is always null. I've checked Request.Form and it is populated with the data I have submitted. I've tried a few different types for the parameter (IEnumerable, IList) but that doesn't make any difference. So I'm wondering if my input fields are set up correctly.. Currently they are in the following format:
The naming convention of each element is based off what I have found referenced here for standard controllers. I'm just wondering if anyone knows why my form values aren't coming through correctly? Hopefully its really obvious! Thanks
Finally figured this out! Basically, because I was using question numbers starting from 1, I also passed that in as the @index for the inputs on the page. This number needs to start at 0 otherwise it seems asp.net doesn't work out that it is a list.
is working on a reply...