我的应用程序中有视图,模型和控制器。我需要的是将文本框值传递给视图并显示在结果页面上。
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>
这似乎是一个愚蠢的问题,但我无法找到它没有显示我输入文本框的用户名的原因。该值可在控制器中访问,但不能在视图中访问。
答案 0 :(得分:3)
您没有将模型传递给视图。
在控制器中,将const httpProxy = require('http-proxy');
const apiProxy = httpProxy.createProxyServer(
{
prependPath: false,
ignorePath: true,
changeOrigin: true,
xfwd: true,
}
);
app.all("/getIframe", function(req, res) {
apiProxy.web(req, res, {target: "http://www.example.com"});
});
更改为return View("Validateresult");