How to pass variables to Ajax.BeginForm

2

Hi, I am new in c# and I need to pass in the following función(PostFailure) in js a variable string of c# . The problem is that the message parameter has a json that I can not understand where it comes from. My current code is:

Index.cshtml

@using (Ajax.BeginForm("Login", "Account", new AjaxOptions {
HttpMethod = "post", OnBegin = "PostOnBegin", OnFailure =
"PostFailure", OnSuccess = "PostSuccess", OnComplete =
"PostOnComplete" })) {...

anylib.js

function PostFailure(message){

}

The idea would be:

Index.cshtml

@using (Ajax.BeginForm("Login", "Account", new AjaxOptions {
HttpMethod = "post", OnBegin = "PostOnBegin", OnFailure =
"PostFailure(messaje,'hola')", OnSuccess = "PostSuccess", OnComplete = 
"PostOnComplete" }))

anylib.js

function PostFailure(message,x){

}

but I miss compilation error.

    
asked by gvivetapl 02.02.2016 в 15:59
source

1 answer

1

It would not be simpler if you use

function PostFilure(){
   var  x= 'hola';
   var mensaje = $('#control').val();

}

or you get the value of a dynamic way of controlling that data

If it's contextual, you can define

@using (Ajax.BeginForm("Login", "Account", new AjaxOptions { HttpMethod = "post", OnBegin = "PostOnBegin", OnFailure = "PostFailure", OnSuccess = "PostSuccess", OnComplete = "PostOnComplete" })) {

    @Html.Hidden(x=> x.Prop);

    <!--resto html-->
}

with a hidden and take it from there using

var mensaje = $('#hiddenId').val();

Where I point is that the parameters are assigned to hidden within the context of the Ajax.BeginForm to take it for jquery instead of passing it by parameter.

    
answered by 02.02.2016 / 16:11
source