Reputation: 3816
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?
Upvotes: 0
Views: 249
Reputation: 25231
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.
Upvotes: 1