1

I'm trying to pass an array from my controller to my view using my Model. My method does not work for some reason. I've posted it below.

Controller:

 public ActionResult Confirmation()
    {
        string[] Array = new string[2] {"Pending", "07/07/2013"};
        ConfirmationModel Con = new ConfirmationModel
        {
            Status = Array[0],
            AppDate = Array[1],

        };
        return View();
    }

Model:

public class ConfirmationModel
    {
        public string Status { get; set; }
        public string AppDate { get; set; }
    }

View:

@model site.ConfirmationModel
@{
    ViewBag.Title = "Confirmation";
}

@Html.DisplayFor(Mode => Model.Status)
@Html.DisplayFor(Mode => Model.AppDate)

4 Answers 4

6

You aren't passing your model to your view. Change the line below:

return View();

To this;

return View(Con);
Sign up to request clarification or add additional context in comments.

Comments

4

You haven't actually included the model in the result. Do this:

return View(Con);

1 Comment

Sometimes it just takes a second set of eyes.
0

You should return populated model to your view. In your case:

return view(con)

Then use con in your view.

Comments

0

You're not passing any model to the view to be rendered.

The View() method has an overload to receive an object model to render in the view.

Try this: return View(Con);

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.