0
我的應用程序中有一個視圖,模型和控制器。我需要的是將文本框的值傳遞給視圖並顯示在結果頁面上。VIew未訪問模型值
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」);'to'return View(「Validateresult」,model);' – User3250