Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 强制ASP.NET MVC 5中的HTTP GET查询参数在其viewmodel属性成员名称被大写时全部为小写_Asp.net Mvc - Fatal编程技术网

Asp.net mvc 强制ASP.NET MVC 5中的HTTP GET查询参数在其viewmodel属性成员名称被大写时全部为小写

Asp.net mvc 强制ASP.NET MVC 5中的HTTP GET查询参数在其viewmodel属性成员名称被大写时全部为小写,asp.net-mvc,Asp.net Mvc,我不确定这是否可行,但接下来 在我的项目中,我有一些viewmodel,它们的所有属性成员名称都是大写的,我使用FormMethod.HttpGet和HTMLHelper(例如EditorFor())创建了一个表单,在提交表单时,助手使用成员属性名称作为表单元素名称(例如),我捕获viewmodel(ActionResult-method(ViewModel-model))在action方法中。我使用的是FormMethod.HttpGet,由于没有JavaScript无法使用此路由,因此表单元

我不确定这是否可行,但接下来

在我的项目中,我有一些viewmodel,它们的所有属性成员名称都是大写的,我使用
FormMethod.HttpGet
和HTMLHelper(例如
EditorFor()
)创建了一个表单,在提交表单时,助手使用成员属性名称作为表单元素名称(例如
),我捕获viewmodel(
ActionResult-method(ViewModel-model)
)在action方法中。我使用的是
FormMethod.HttpGet
,由于没有JavaScript无法使用此路由,因此表单元素在URL中被解析为查询参数


因为所有的视图模型都是大写的,所有的表单参数也都是大写的,我有一种明显的感觉,这可能会在将来的某个地方造成问题,无论是JsonResult格式还是SEO,或者其他我不知道的事情,但我更希望它们是小写的,但关键是,我不知道我是否需要c您可以在保持ViewModel成员属性大写的同时执行此操作。

您可以使用小写URL,这是ASP.NET MVC中的可选配置设置

在ASP.NET 4中:

{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.LowercaseUrls = true;

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
在ASP.NET 5中:

public void ConfigureServices(IServiceCollection services)
{
// ...
    services.ConfigureRouting(routeOptions =>
    {
        routeOptions.AppendTrailingSlash = true
        routeOptions.LowercaseUrls = true;
    });
}
}
对于HttpGet

  • 在使用
    toLowerCase()
    方法构建url或传递的参数后,可以使用javascript将其小写

  • 或者,正如前面提到的
    CodeCaster
    一样,创建一个HTMLHelper以在cshtml中使用,例如

    @Html.LowerTextBoxFor(x=>x.Property1)
    
如果你想在搜索引擎优化中使用小写,你也可以使用web服务器扩展来使用小写URL,例如

关于JSON大写,也有相应的配置选项,例如在ASP.NET 5中,可以将C#PascalCase转换为JSON使用的camelCase

services.AddMvc()
.AddJsonOptions(options =>
{
    options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
    options.SerializerSettings.DefaultValueHandling = DefaultValueHandling.Ignore;
    options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;

}); 

这就是我想要的,谢谢。我需要学习如何正确地搜索。