与查询字符串不同的变量名称 [英] Different variable name from querystring

查看:64
本文介绍了与查询字符串不同的变量名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的控制器有一个对象作为参数

My controller has an object as parameter

Function Search(ByVal model As ItemSearchModel) As ActionResult

看起来像这样

Public Class ItemSearchModel

    Public Property SearchQuery As String

而且,正如您可以想象的那样,该网址看起来像这样

And, as you can imagine, the url will look this like

/Search?SearchQuery=test

我想将查询字符串更改为一个小变量,类似

I want to change the query string to have a small variable, sort of like

/Search?s=test

是否有内置的方法可以在班级中保留相同的变量名?像

Is there a built-in way I could keep the same variable name in my class? Something like

Public Class ItemSearchModel

    <QueryString(Name:="s")> _
    Public Property SearchQuery As String

推荐答案

我认为您可以使用

I think you can use the ActionParameterAlias package from Nuget to accomplish what you want.

这篇关于与查询字符串不同的变量名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆