0

Let me see if I can make it more clear of what im looking for.

I have a view 'UpdateLead'

on the GET in my controller I have..

[HttpGet]
public ActionResult UpdateLead()
{
    LoginUser user = Session["User"] as LoginUser;
    if (user != null)
    {
         BusinessLead bl = new BusinessLead();
         bl.Name = "some stuff";

         return View(bl1);
    }
    return RedirectToAction("Login", "Main");
}

SO when I see the View, the 'name' field has text "some stuff"..

but what i want is basically to get that 'name' information from a gridview that is on another view called 'ViewLeads'. The gridview is an Infragistics grid. So basically if the user selects the 3rd user in the grid, I want to return all the data for that user (user ID 3). Im very new to MVC and I'm totally lost right now. Thanks!

tereško
  • 58,060
  • 25
  • 98
  • 150
Omar
  • 129
  • 3
  • 12

1 Answers1

0

You could add a parameter of name to the action. If I understand what you're doing in your code correctly....

[HttpGet]
public ActionResult UpdateLead(String name = "")
{
    if (!String.IsNullOrEmpty(name))
    {
        LoginUser user = name as LoginUser;
        BusinessLead bl = new BusinessLead();
        bl.Name = "some stuff";

        return View(bl1);
    }
    if (user != null)
    {
        LoginUser user = Session["User"] as LoginUser;
        BusinessLead bl = new BusinessLead();
        bl.Name = "some stuff";

        return View(bl1);
    }
    return RedirectToAction("Login", "Main");

}

To do this by Id:

[HttpGet]
public ActionResult UpdateLead(Int32 UserId = -1)
{
    LoginUser user = Session["User"] as LoginUser;
    if (UserId > -1)
    {
        BusinessLead bl = new BusinessLead();
        bl.Name = "some stuff";
        bl = GetUserInfoById(UserId);    // Some method you need to make to populate your BusinessLead class based on the id field
        return View(bl1);
    }
    if (user != null)
    {
        BusinessLead bl = new BusinessLead();
        bl.Name = "some stuff";

        return View(bl1);
    }
    return RedirectToAction("Login", "Main");

}

You could then use Html.ActionLink in your gridview

@Html.ActionLink(UserName, "UpdateLead" "ControllerName", new {name=UserName}, null)

Regarding your comment: Html.ActionLink generates the link for you. If you wanted to incorporate this manually, you could try something like this:

column.For(x => x.Name).Template("<a href='UpdateLead?name=${Name]'style='color:blue;'>${Name}</a>").HeaderText("Name").Width("10%‌​");

Edit I just noticed that you mentioned (user ID 3). You can do the same thing by passing an integer. You can either have it nullable and check the value, or default it to 0 or some other number that it could never be to check against.

Community
  • 1
  • 1
  • How could I incorporate that in my infragistics grid? my grid code looks like... column.For(x => x.Name).Template("${Name}").HeaderText("Name").Width("10%"); – Omar Aug 21 '14 at 18:41
  • Hi Omar, you may want to include that code in your question inside a code block! It's difficult to read in a comment. With that in mind, you could append `?name=$[Name]` to your href. – disappointed in SO leadership Aug 21 '14 at 18:43
  • Sorry about that. Thanks! so I tried that and now it's passing the name. Would I need to do the same for all other fields? Or would passing the ID like said give all the values from the grid that I need? – Omar Aug 21 '14 at 19:06
  • If you have a way of getting the data by the id, then yes, the Id would be best. You could also do a lookup based on the name, but it's a better practice to do it by id where the id is unique, and the name isn't always unique. How you'd do that all depends on how you have your data stored. – disappointed in SO leadership Aug 21 '14 at 19:08