Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

183
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda