aspnetcore mvc默认可以处理ajax的put,delete之类的操作,可是表单form提交就找不到路由了。
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
...
app.UseHttpMethodOverride(new HttpMethodOverrideOptions {
FormFieldName = "_method"
});
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
添加上HttpMethodOverride中间件就可以把通过在表单加入下面的方式模拟put,delete类提交操作.
<input type="hidden" name="_method" value="put" />