c# - 使用模型将数组从 Controller 传递到 View

标签 c# asp.net-mvc asp.net-mvc-4 model-view-controller

我正在尝试使用我的模型将一个数组从我的 Controller 传递到我的 View 。我的方法由于某种原因不起作用。我已经在下面发布了。

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

模型:
public class ConfirmationModel
    {
        public string Status { get; set; }
        public string AppDate { get; set; }
    }

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

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

最佳答案

您没有将模型传递给您的 View 。更改以下行:

return View();

对此;
return View(Con);

关于c# - 使用模型将数组从 Controller 传递到 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18500514/

相关文章:

javascript - 如何在 html 中显示表示 XML 的字符串?

javascript - knockout 从输入到函数的发送值

c# - 从内存中读取文件的第一行

html - 如何仅添加部分 View 所需的脚本和 css 文件

asp.net - Spark-View-Engine 与 ASP.NET MVC2

c# - 启动 ASP.NET MVC 4 应用程序时执行代码

javascript - ASP.NET MVC4 添加评论后刷新 View

c# - 用于匹配 2 个括号内的子字符串的正则表达式,例如[我想要这段文字] 但是去掉括号?

C# 4.0 从 Parallel.ForEach 中访问表单控件

c# - JsonSerializer.CreateDefault().Populate(..) 重置我的值