简体   繁体   English

可以将公共操作参数映射到MVC 4 C#中的不同字段

[英]Possible to map public action parameters to different fields in MVC 4 c#

So say I have a action that looks like: 假设我有一个类似的动作:

public ActionResult SomeAction(string ovar_token1, string ovar_token2, string some_other)
{
    // Do some stuff here
}

What I would like to do is have the parameters called something else that is more agreeable to our naming conventions while still permitting the modelbinding to bind to them. 我想做的是将参数称为其他名称,这与我们的命名约定更加一致,同时仍允许将模型绑定绑定到它们。

So probably decorating with some custom annotation like: 所以大概用一些自定义注释来装饰:

[Params("ovar_token1", token)]
[Params("ovar_token2", token2)]
[Params("some_other", data)]
public ActionResult SomeAction(string token1, string token2, string data)
{
    // Do some stuff here
}

Anyone ever tried this? 有人尝试过吗?

You are looking for BindAttribute : 您正在寻找BindAttribute

public ActionResult SomeAction(
    [Bind(Prefix="ovar_token1")]string token1,
    [Bind(Prefix="ovar_token2")]string token2,
    [Bind(Prefix="some_other")]string data)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM