0

I am opening a aspx page "Test.aspx" from a mvc view using Window.showModelDialog(),and this page is returning some value in a JavaScript function(window.returnValue) on that MVC view,Now I have to bind this value to model property and pass it to Controller.How to bind this value to Model and pass it Controller?

1 Answer 1

1

The default model binder tries to match POST variable names to model property names. This means that you can dynamically add fields that will be bound to model properties at any point, as long as the variable name in the eventual POST matches the model property.

Create a hidden field, whose name property matches the name of your model property:

<input type="hidden" id="hdnMyProperty" name="MyProperty" />

Then use jQuery to populate the field's value when you close your dialog:

var property = /* Your returned value here */;
$('#hdnMyProperty').val(property);

If the property's value can be bound to the model property in question, the model binder will take care of the rest when you submit your main form.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.