3

Index.chtml page itself i have this link

@Html.ActionLink("Edit","EditUserProfile",new {vchUserID = item.vchUserID})

Inside user Controller itself

// GET: /User/ViewUserProfile/1
public ActionResult EditUserProfile(string userID = "abdul@kareems.com")
{
    LIVE_USER objUserFind = db.LIVE_USER.Find(userID);

    if (objUserFind == null)
    {
        return HttpNotFound();
    }

    return View(objUserFind);

}

//
//POST: /Admin/EditAdminProfile/1
[HttpPost]
public ActionResult EditUserProfile(LIVE_USER objUserFind)
{
    if (ModelState.IsValid)
    {
        db.Entry(objUserFind).State = EntityState.Modified;
        db.SaveChanges();
        return RedirectToAction("Index");
    }
    return View(objUserFind);
}

RouteConfig.cs file itself i have url structure like bellow.

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{vchUserID}",
            defaults: new { controller = "Admin", action = "Index", vchUserID = UrlParameter.Optional /*kareem removed vchUserID = UrlParameter.Optional*/         }
        );

Result i got is: *HTTP Error 404.0 - Not Found The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.*

KMS
  • 95
  • 14
  • Your question is bit confusing. Do you want to invoke a method using @Html.ActionLink and pass user email id as parameter to the controller method? Or do you want to return the email id from the controller method to the view based on the user id? – Girish Sakhare Dec 30 '13 at 08:13
  • Please refer http://stackoverflow.com/questions/8293934/passing-parameter-to-controller-action-from-a-html-actionlink – Girish Sakhare Dec 30 '13 at 08:16

1 Answers1

3

The name of the parameter in your controller method needs to match the name of the parameter defined in your route. Currently the parameter is named vchUserID in the route but in your controller method you have named it userId.

That means the controller method will never get the value from the Url, and you will always get the default value "abdul@hibrise.com". (I guess that is not one of your live users so you are returning the HttpNotFound result)

Try renaming the parameter in the controller method as in:

public ActionResult EditUserProfile(string vchUserID = "abdul@hibrise.com")
{
    ...
}
Daniel J.G.
  • 34,266
  • 9
  • 112
  • 112
  • thanks; your absolutely correct, problem is correct but later i found on somewhere here. @Html.ActionLink("Edit","EditUserProfile",new {vchUserID = item.vchUserID}) – KMS Dec 30 '13 at 10:29