如何在控制器中传递字符串值 [英] How to pass string value in controller
本文介绍了如何在控制器中传递字符串值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将字符串值(UserId)从一个控制器传递给http post动作结果(按钮clik)
我尝试过:
I want to pass string value(UserId) from one controller to http post action result(button clik)
What I have tried:
public ActionResult Login(string UserId)
{
// string mail = Decrypt(UserId);
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Login(UserProfile objUser)
{
//string EncryptedID = Decrypt(objUser.UserId);
if (ModelState.IsValid)
{
using (DBEntities db = new DBEntities())
{
var obj = db.UserProfiles.Where(a => a.UserName.Equals(objUser.UserName) && a.Password.Equals(objUser.Password)).FirstOrDefault();
if (obj != null)
{
Session["UserId"] = obj.UserId.ToString();
Session["UserName"] = obj.UserName.ToString();
return RedirectToAction("UserDashBoard");
}
}
推荐答案
您可以与<$ c一起创建锚标记$ c> @ Url.Action 方法,因此当用户点击它时,它会调用登录操作并发布UserId
价值IdHere
目前:
You can create a anchor tag in combination with@Url.Action
method, so when the user will click it, it will call the Login action and will post theUserId
with valueIdHere
for now:
<a href="@Url.Action("Login","ControllerName", new {UserId = "IdHere"})"
或者您可以使用按钮元素,例如:
or you can use the button element as well like:
<button class="btn btn-info" type="button" id="addressSearch"
onclick="location.href='@Url.Action("Login","ControllerName", new {UserId = "IdHere"})'">
希望它能帮助你理解如何处理这个问题。
谢谢,
Ehsan
Hope it helps you to understand how to approach this.
Thanks,
Ehsan
这篇关于如何在控制器中传递字符串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文