[英]Unable to post data using ASP.NET MVC6
I am low mvc6 and c# skills, I am trying to post, when I sumbit it's doing nothing. 我的mvc6和c#技能不高,我想发布,当我总结时它什么也没做。
It wont take me to the controller, just stays on the page. 它不会带我去控制器,只是停留在页面上。
I have more pages, I dont know where is the problem, I will add the rest if need 我的页面更多,我不知道问题出在哪里,如有需要,我将添加其余页面
Here my Controller : 这是我的控制器 :
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebApplication1.ViewModels;
namespace WebApplication1.Controllers.Web
{
public class AppController : Controller
{
public IActionResult Index()
{
return View();
}
public IActionResult Contact()
{
return View();
}
[HttpPost]
public IActionResult Contact(ContactViewModel model)
{
return View();
}
public IActionResult About()
{
return View();
}
}
}
here my Contact: 这是我的联系方式:
@model WebApplication1.ViewModels.ContactViewModel
@{
ViewBag.Title = "Contact Page";
}
@section scripts{
<script src="~/lib/jquery-validation/dist/jquery.validate.js"></script>
<script src="~/lib/jquery-validation- unobtrusive/jquery.validate.unobtrusive.min.js"></script>
}
<h2>Contact Me</h2>
<form method="post">
<span asp-validtaion-summary="ModelOnly"></span>
<label asp-for="Name"></label>
<input asp-for="Name"/>
<span asp-validation-for="Name"></span>
<label asp-for="Email"></label>
<input type="email" asp-for="Email"/>
<span asp-validation-for="Email"></span>
<label asp-for="Message"></label>
<textarea cols="40" rows="4" asp-for="Message"></textarea>
<span asp-validation-for="Message"></span>
<div>
<input type="submit" value="Send Message" />
</div>
</form>
You forgot to tell the "form" what to do, when the user submits it. 您忘记了在用户提交表单时告诉“表单”要做什么。 For MVC6 you can use this tag helper:
对于MVC6,您可以使用以下标记帮助器:
<form asp-controller="App" asp-action="Contact">
...
</form>
This will output something like 这将输出类似
<form action="/App/Contact" method="post">
And now the Browser knows the action url and where to send to data. 现在,浏览器知道了操作URL和发送数据的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.