Ask Your Question
2

What is the method for passing the ID using @Html.Partial in ASP.NET MVC or Http session ID?

asked 2023-06-27 09:45:10 +0000

scrum gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-06-27 10:10:01 +0000

ladyg gravatar image

The method for passing the ID using @Html.Partial in ASP.NET MVC is by passing the ID as a parameter to the partial view, like this:

@Html.Partial("_PartialViewName", ID)

Then in the partial view, you can access the ID using the model, like this:

@model int
<p>My ID is @Model</p>

Alternatively, you can store the ID in the Http session and retrieve it in the partial view like this:

@{
    int ID = (int)Session["ID"];
}
@Html.Partial("_PartialViewName", ID)

Then in the partial view, you can access the ID like before, using the model. However, this method requires that you have set the ID in the Http session before calling the partial view.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-27 09:45:10 +0000

Seen: 9 times

Last updated: Jun 27 '23