【发布时间】:2015-01-08 18:10:52
【问题描述】:
我对所有这些 MVC4 和 ASP .NET 都是新手,我试图制作一个简单的表单来获取文本,然后将其提交到另一个视图并在那里打印,我已经搜索了教程和数据,但仍然不知道如何这样做,我制作了表单视图并获取了要转到控制器的值,这是我的代码:
控制器:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcApplication10.Controllers
{
public class HomeController : Controller
{
[HttpGet]
public ActionResult Index()
{
ViewBag.Message = "Modifique esta plantilla para poner en marcha su aplicación ASP.NET MVC.";
return View();
}
[HttpPost]
public ActionResult Index(string text) {
return RedirectToAction("About", "Home");
}
public ActionResult About()
{
ViewBag.Message = "Página de descripción de la aplicación.";
return View();
}
}
查看
@{
ViewBag.Title = "Página principal";
}
<h3>Formulario</h3>
@using (Html.BeginForm())
{
@Html.Label("Escribe lo que quieras")<br />
@Html.TextArea("text")<br />
<button type="submit">Enviar</button>
}
这就是我目前所拥有的。
【问题讨论】:
-
你需要一个“for”助手(除了显示)来将你的数据绑定到模型
标签: c# asp.net asp.net-mvc forms asp.net-mvc-4