Get value of a Javascript function in a variable C # mvc5

0

I need to store what returns a JavaScript function inside a variable in a C # view with razor in mvc 5.

For example, what this function returns:

    function fechafin(){
    var ff = document.getElementById("ffin").value;
    return ff;
}

Store it in a variable of the type view:

@{var variableLocal = *el valor que retorna la funcion*

Any ideas? Thanks in advance.

    
asked by Rob 21.06.2018 в 06:02
source

1 answer

0

Razor is a page rendering engine in the sense that Razor pre-processes the html of a cshtml or vbhtml file for deliver it to the customer. This means that Razor "arms" the HTML that will be delivered to the browser. It has nothing to do with JavaScript (although in the HTML that generates it can and in fact it usually send JS lines).

On the other hand, JavaScript does not run on the server (for that matter) but on the client when it receives it. Everything that happens in Javascript stays with the client. Unless ...

Asynchronous requests

The traditional way to send data from the client to the server is through forms <form> . However, for years Ajax has offered us an alternative. With a <form> you have to trigger the event send with a button <button type="submit"> and at the moment of doing it, the data travels to an address that processes them and returns a new page (that is, you send and you have to wait for a new full page to download).

With Ajax it is no longer necessary, but you can schedule requests to the server (with or without data, as if it were a form) at any time and without having to wait for a full download. new page, but only a piece of information. This information can travel in XML format (a document with <tags> defined by you) or in JSON (a "string" of text with a structure of clave:valor ) that are the information exchange formats.

To achieve what you want, what you need is to make requests of this kind. I leave you some literature about it:

answered by 02.08.2018 в 17:22