mvc3 request.querystring 抛出 null 错误

发布于 2024-11-26 16:08:11 字数 793 浏览 4 评论 0原文

我在 mvc3 应用程序中检索查询字符串并验证电子邮件时遇到问题。 我想做的事情是获取查询字符串值并将其传递给要执行的方法,但是当我从控制器检索该值时,查询字符串具有该值,但是当我采用变量并将查询字符串值分配给它时,它显示空值。这是为什么?

这是我的控制器代码

    public ActionResult LogOn()
    {

        if (HttpContext.Request.QueryString["EmailId"] != string.Empty)
        {
            var q = Request.QueryString["EmailId"];
            userMgr = new UserManager();

            MyDoctor.Models.DocUser user = userMgr.GetByEmailForExistUser(Request.QueryString["EmailId"]);
            try
            {
                user.Status = true;
                user.UpdatedDate = System.DateTime.Now;
                userMgr.Update(user);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        return View();
    }

i have the problem of retrieving the querystring and verifying the email in mvc3 application.
The thing i want to do is get the querystring values and pass it to a method to execute but when i retrieve the value from the controller the querystring is having the value but when i take a variable and assign the querystring value to it, then it is showing null value. why is this?

This is my controller code

    public ActionResult LogOn()
    {

        if (HttpContext.Request.QueryString["EmailId"] != string.Empty)
        {
            var q = Request.QueryString["EmailId"];
            userMgr = new UserManager();

            MyDoctor.Models.DocUser user = userMgr.GetByEmailForExistUser(Request.QueryString["EmailId"]);
            try
            {
                user.Status = true;
                user.UpdatedDate = System.DateTime.Now;
                userMgr.Update(user);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        return View();
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼眸里的快感 2024-12-03 16:08:11

因为它是 null :)

您可能需要将 if 语句更改为如下所示:

if( !string.IsNullOrEmpty( HttpContext.Request.QueryString["EmailId"] ) )

Because it is null :)

You might need to change your if statement to something like this:

if( !string.IsNullOrEmpty( HttpContext.Request.QueryString["EmailId"] ) )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文