Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6023321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:59:15+00:00 2026-05-23T03:59:15+00:00

I am trying to access the Route value of id from inside the PartialView.

  • 0

I am trying to access the Route value of id from inside the PartialView. I have a Post, Comments scenario. And I want my Comments partialview to have access to the PostId.

The Url looks like the following:

Posts/Detail/2

Now, how can I access the value 2 inside the Partial View?

UPDATE:

I changed my CommentsController to the following:

 public ActionResult Add(string id,string subject,string name,string body)
{

}

But now when I debug it does not even step into the Add method.

UPDATE 2:

My partial view looks like the following:

<div class="title">Add Comment</div>

@using (Html.BeginForm("Add","Comments",FormMethod.Post))
{
    @Html.Label("Subject") 
    @Html.TextBox("subject")
    <br />
    @Html.Label("Name") 
    @Html.TextBox("name") 
    <br />
    @Html.Label("Body") 
    @Html.TextBox("body") 




    <input type="submit" value="submit" />                            
}

And here is the Controller:

 public ActionResult Add(string id, string subject, string name, string body)

If I remove id from the above controller action then it works.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:59:16+00:00Added an answer on May 23, 2026 at 3:59 am

    You could fetch it from RouteData:

    In WebForms:

    <% 
        var id = ViewContext.RouteData.Values["id"];
    %>
    

    In Razor:

    @{
        var id = ViewContext.RouteData.Values["id"];
    }
    

    After showing your code it seems that in your form you are not passing the id. So modify it like this:

    @using (Html.BeginForm("Add", "Comments", new { id = ViewContext.RouteData.Values["id"] }, FormMethod.Post))
    {
        ...
    }
    

    or use a hidden field if you prefer:

    @using (Html.BeginForm("Add", "Comments", FormMethod.Post))
    {
        @Html.Hidden("id", ViewContext.RouteData.Values["id"])
        ...
    }
    

    Now you should get the id in your Add controller action.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to access Outlook 2007 from C#. I have installed the PIA
Trying to access a Servlet from a button on HTML page //Html Page FORM
Im trying to access a web service from a remote computer. I managed to
I'm trying to access a second xmldom in a loop. <c:import var=some1xml url=/xml/some1.xml/> <c:import
I'm trying to pull a value out of the url query string however I
I'm trying to parse json data from google directions but can't seem to access
I am trying in the for loop to access the value of the i
using Rails 3.1.0.rc4, I'm trying to access a route helper in a javascript file
When trying to access the following URL, I get a 404 error page :
I'm trying to access a simple ASP.NET MVC route, but it's erroring with: The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.