简体   繁体   中英

Passing an array from Controller to View using Model

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)

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

return View();

To this;

return View(Con);

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

return View(Con);

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

return view(con)

Then use con in your view.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM