【问题标题】:Different way to pass query string value through URL to ActionResult Method using ASP.NET MVC 5 Entity Framework使用 ASP.NET MVC 5 Entity Framework 通过 URL 将查询字符串值传递给 ActionResult 方法的不同方法
【发布时间】:2019-01-09 22:17:22
【问题描述】:

我正在将查询字符串值邮件程序 url 传递给操作方法。

我正在将下面的 URL 传递给我的激活 ActionResult

body += "Please click <a href=" + LinkPath + "Registers/Activation?emailId=" + emailid + "&uCode=" + activationCodes + "&type=" + a + ">here</a> to active your account" + "<br><br>";

我可以将查询字符串值传递给如下操作方法吗?激活是我的操作方法:

www.xyz.com/Registers/Activation?emailId=mazharkhan@gmail.com&uCode=12458475

我还在我的Activation 方法中获得了一个查询字符串值,如下所示

Request.QueryString["emailId"].ToString();

实际上,我以前使用 ASP.NET Web 表单的经验现在我正在使用 ASP.NET MVC 5 和 Entity Framework。

我的问题是可以在我的邮件程序中传递查询字符串值,例如 web 表单。

【问题讨论】:

    标签: c# asp.net asp.net-mvc-5 query-string


    【解决方案1】:

    参数原语在 GET 请求的 URL 中传递。

    MVC 通过模型绑定将查询字符串参数映射到方法参数。所以你可以像这样简单地写你的Controller和你的Action

    public class YourController: Controller
    {
        [Route("Registers/Activation")]
        public ActionResult Get(string emailId, string codeType, string type)
        {
        }
    }
    

    使用Request.QueryString 有效,但在 MVC 中应该如何完成这是错误的。

    【讨论】:

    • 我的查询字符串 url 有什么问题并解释一下。 @蒂埃里 V
    • 发送参数很好,例如:www.xyz.com/Registers/Activation?emailId=mazharkhan@gmail.com&uCode=12458475 和接收参数我认为我们不应该像 Request.QueryString 那样使用。 @蒂埃里 V
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-31
    • 1970-01-01
    • 1970-01-01
    • 2013-11-06
    • 2011-03-29
    • 2020-03-29
    相关资源
    最近更新 更多