【发布时间】:2017-05-30 08:57:45
【问题描述】:
我的应用程序中有一个视图、模型和控制器。我需要的是将文本框值传递给视图并显示在结果页面上。
Index.cshtml
@model MvcApplication5.Models.Employee
@{
ViewBag.Title = "Dashboard";
}
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<h2>Dashboard</h2>
<div>
<h1>Employee </h1>
</div>
@using (Html.BeginForm("DisplayForm", "Dashboard", FormMethod.Post))
{
@Html.EditorFor(model =>model.username)
@Html.TextBoxFor(model => model.Company)
<button type="submit" id="ajax_method">submit </button>
}
控制器
public ActionResult DisplayForm(Employee model)
{
var employeeName = model.username;
var company = model.Company;
return View("Validateresult");
}
Model
public class Employee
{
public string username { get; set; }
public string Company { get; set; }
}
和 validateresult.cshtml
@model MvcApplication5.Models.Employee
<h2>Validateresult</h2>
<div>
<div>username:
@Html.DisplayFor(model => model.username)
</div>
</div>
这似乎是一个愚蠢的问题,但我无法找到它不显示我在文本框中输入的用户名的原因。该值可在控制器中访问,但不能在视图中访问。
【问题讨论】:
-
return View("Validateresult");到return View("Validateresult",model);
标签: asp.net-mvc asp.net-mvc-4 model-view-controller