I'm using MVC3 and passing a adminEditViewModel viewmodel to my view:
public class adminEditViewModel
{
public Answer Answer { get; set; }
public string abc { get; set; }
}
The Class Answer looks like this:
public class Answer
{
public string[] ImageFile;
}
In the view I use this:
@Html.EditorFor(model => @Model.Answer.ImageFile[@index])
When it's on the page it looks like this:
<div class="editor-field">
<input class="text-box single-line" id="Answer_ImageFile_0_" name="Answer.ImageFile[0]" type="text" value="" />
</div>
When it's returned to the controller with the viewmodel above as a parameter I add some data, set a debug point, click submit and then see that Answer class in the viewdata contains null but other things such as abc are correctly set.
My ques开发者_StackOverflowtion is can I even return data through a viewmodel from an array like this in the normal way?
Hope for some good advice
since asp.net mvc advocates convention over configuration, generated html has to be in some standard format to be bound with list or array of values in your model. plz look at this question. the answer contains a link to steve senderson's post on binding list values to controller action parameter.
Your Answer.ImageFile is a field; ASP.NET MVC binds to properties only.
public class Answer
{
public string[] ImageFile { get ;set; }
}
精彩评论