Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

180
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda