How to get value from an Html.EditorFor

0

I have the following command

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

On it is placed a date, and when clicking a button it should redirect to a report, except that I need to pass to the URL the parameter Data shutdown to send to 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 this.

    
asked by anonymous 11.04.2018 / 22:23

1 answer

1

You can do with javascript a function to get 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 id the same property name.

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

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

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

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