使用 ASP.NET MVC 5 Entity Framework 通过 URL 将查询字符串值传递给 ActionResult 方法的不同方式
Different way to pass query string value through URL to ActionResult Method using ASP.NET MVC 5 Entity Framework
我正在将查询字符串值邮件程序 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 网络表单,现在我正在使用 ASP.NET MVC 5 和 Entity Framework。
我的问题是在我的邮件程序中像网络表单一样传递查询字符串值是可以的。
参数原语在 URL 中传递给 GET
请求。
MVC 通过模型绑定为您将查询字符串参数映射到方法参数。所以你可以像这样简单地写你的Controller
和你的Action
:
public class YourController: Controller
{
[Route("Registers/Activation")]
public ActionResult Get(string emailId, string codeType, string type)
{
}
}
使用 Request.QueryString
可行,但就如何在 MVC 中完成而言这是错误的。
我正在将查询字符串值邮件程序 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 网络表单,现在我正在使用 ASP.NET MVC 5 和 Entity Framework。
我的问题是在我的邮件程序中像网络表单一样传递查询字符串值是可以的。
参数原语在 URL 中传递给 GET
请求。
MVC 通过模型绑定为您将查询字符串参数映射到方法参数。所以你可以像这样简单地写你的Controller
和你的Action
:
public class YourController: Controller
{
[Route("Registers/Activation")]
public ActionResult Get(string emailId, string codeType, string type)
{
}
}
使用 Request.QueryString
可行,但就如何在 MVC 中完成而言这是错误的。