0

This is the code I have:

 var IsWithHistory = 1;
 if (stat == 'P') {
    var ans = confirm("Copy product with selection History");
    if (ans == true) {
        $("#CopyProductHeaderForm").submit();
    } else {
        IsWithHistory = 0;
        $("#CopyProductHeaderForm").submit();
    }
 }

CopyProductHeaderForm is going to my controller with this Can I send IsWithHistroy Value to the controller? how to send this value to the controller to check the condition.

Thanks

4 Answers 4

2

You include a hidden field inside this form:

<%= Html.Hidden("IsWithHistory") %>

and then you set its value before submitting:

$('#IsWithHistory').val(IsWithHistory);
$('#CopyProductHeaderForm').submit();

Now the controller will get the IsWithHistory value.

Sign up to request clarification or add additional context in comments.

Comments

1

Add a hidden field to the form and manipulate that before submitting.

Example:

<form id="CopyProductHeaderForm">
...
<input type="hidden" id="IsWithHistory" value="1"/>
...
</form>

<script>
  if (stat == 'P') {
    if (!confirm("Copy product with selection History")) {
      $("#IsWithHistory").val(0);
    }
    $("#CopyProductHeaderForm").submit();
  }
</script> 

Comments

1

Add a hidden input field to your form (either in HTML or using Javascript) and set the value of that hidden input field to IsWithHistory.

Comments

1

You only need to create an input in your form, say a hidden one here. Set its name to IsWithHistory and set it's value to your javascript var.

Then in your controller action add a parameter int IsWithHistory.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.