How to get value from an Html.Editorfor

Asked

Viewed 380 times

0

I have the following command

@Html.EditorFor(m => m.DataDoDesligamento)

In it is placed a date, and when clicking on a button should redirect to a report, only that I need to pass the parameter dateDesligment to send the specific report, as follows.

<a target="_blank" type="button" class="btn btn-red" href="~/Relatorio/Relatorio.aspx?dataReferencia=@dataDesligamento">Simular desligamento</a>

And I have no idea how to do that.

  • Use can be easily solved in Javascript, you are using [tag:Jquery]?

  • How I can solve through this?

  • On the front end of the page, you will get the value of the field when the user clicks the go to report button (I will create my answer with more information), you did not answer my question, you are using Jquery in your project?

  • @Thaynavaladares Be more specific. What is the code that generates that href?

  • Not being used jquery

1 answer

1

You can do with javascript a function to take the value of @Html.EditorFor(m => m.DataDoDesligamento), create a URL and open on a page with that URL.

The helper EditorFor will generate an element that has as id the same name as the property.

So, inside your page, add 1 button and in the event onclick call on the function redirecionar() that we will create.

<button onclick="redirecionar()" >Simular desligamento</button>

Below, open a tag to write code javascript and create the Function

<script>
    function redirecionar(){
      var dataDoDesligamento = document.getElementById("DataDoDesligamento").value;
      window.open("~/Relatorio/Relatorio.aspx?dataReferencia="+dataDoDesligamento,'_blank');
    }    
</script>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.