1

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 question is can I even return data through a viewmodel from an array like this in the normal way?

Hope for some good advice

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

Your Answer.ImageFile is a field; ASP.NET MVC binds to properties only.

public class Answer
{
    public string[] ImageFile { get ;set; }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.