Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
Passing innerHTML from View as a parameter to an ASP.NET Controller

I have a @Url.Action ASP.NET Method that looks similar to the code below:

<h1 class="sidebar-item custom-heading" id="heading-info" href="#">*Dynamically Changing Header*</h1>
    <a class="sidebar-item" onclick="javascriptFunction()" href="@Url.Action("Action", "Controller", new {
        name="Dynamically Changing Header",
    })">Link</a>

With The Controller Method looking similar to this:

    public IActionResult Action(string name) { 
// operation
}

My issue I'd like to send the text inside the h1 tag(id="heading-info") to the controller. It's dynamic because a there's a java-script function that changes the innerText when called, however that shouldn't be an issue. Ideally, what I'd want is for whatever text is in between that h1 tag to be sent to the controller whenever that link is clicked. That value will later be validated by the controller.

Let me know if this is at all possible.

EDIT:

This link also handles some properties that should not be seen by the user. The new example is below:

<h1 class="sidebar-item custom-heading" id="heading-info" href="#">*Dynamically Changing Header*</h1>
    <a class="sidebar-item" onclick="javascriptFunction()" href="@Url.Action("Action", "Controller", new {
        // Does not matter if seen by client
        name="Dynamically Changing Header",

        // Should not be seen by Client
        importantPieceOfData1=@ViewBag.Piece1,
        importantPieceOfData2=@ViewBag.Piece2,
        importantPieceOfData3=@ViewBag.Piece3,

    })">Link</a>

So now the controller should look like this:

    public IActionResult Action(string name, string importantPieceOfData1, string importantPieceOfData2, string importantPieceOfData3) { 
         // operation
    }  

Again, all I need is whatever text is in between that h1 tag to be sent to the controller whenever that link is clicked along with the attached server side code that shouldn't be seen.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!