Alex Rivera | Logout

RedirectToAction usage in asp.net mvc

Asked 2010-12-06T02:45:02.617
33

I want to post some questions about ASP.Net MVC. I am not familiar with web developing, But I was assigned to the web part of a project. We are doing the following: first, we create get & set properties for the person data:

public class Person
{
    public int personID {get;set;}
    public string personName {get;set;}
    public string nric {get;set;}
}

and after login, we put the data in a class Person object and we use RedirectToAction like this:

return RedirectToAction("profile","person",new { personID = Person.personID});

It's working normally, but the parameter are shown in the URL. How can I hide them and also can I hide the action name? Guide me the right way with some examples, please.

Edit
Report

1 Answer

1

this may be solution of problem when TempData gone after refresh the page :-

when first time you get TempData in action method set it in a ViewData & write check as below:

public ActionResult Index()
{
    TempData["nickname"] = Person.nickname;
    return RedirectToAction("profile", "person");
}

now on the Profile action :

public ActionResult Profile()
{
    var nickname = TempData["nickname"] as string;

    if(nickname !=null)
        ViewData["nickname"]=nickname;

    if (nickname == null && ViewData["nickname"]==null)
    {
        throw new HttpException(404);
    }
    else
    {
        if(nickname == null)
            nickname=ViewData["nickname"];
    }

    return View();
}
answered 2012-08-26T16:57:58.700

Your Answer