user2503692
user2503692

Reputation: 11

Hide parameter value from URL

I have a URL like this

http://localhost/PW/LeaveWithoutPay/Edit?id=9

and I want to hide the id?=9 from my URL. Can any one demonstrate how to hide this id parameter with an example? I am using Visual Studio 2012.

Upvotes: 0

Views: 695

Answers (2)

prashantchalise
prashantchalise

Reputation: 506

You must need to implement Post method instead of GET method. Here is a sample example for it.

In your controller define something like this

    public ActionResult Edit([FromBody] int id) {
        TempData["MsgText"] = id.ToString();
        return RedirectToAction("Index");
    }

Now in your view, implement the POST method. A sample example is:

@{string id =(string)TempData["MsgText"];}

@using (Html.BeginForm("Edit", "Home", FormMethod.Post, new { id = "frmCallThis" })){

@Html.Label("label",string.IsNullOrEmpty(id)?"No Id Provided":"Current ID = " + id)

@Html.TextBox("id");

<input type="submit" value="Get This Printed" />

}

Finally you have the following output: (Before Submit) enter image description here

And After submit:

enter image description here

Hope this helps,

Upvotes: 1

thangchung
thangchung

Reputation: 2030

Only one thing you have to doing here is using POST, not GET method. Because the web request is usually stateless, so I don't think we have any other methods to hide your id.

Upvotes: 0

Related Questions