mvc3 request.querystring 抛出 null 错误
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为它是 null :)
您可能需要将 if 语句更改为如下所示:
Because it is null :)
You might need to change your if statement to something like this: