Hey...I have view for document upload. I want to have button there whi开发者_JS百科ch will generate more uploads control on click event.Is there a way to generate controls on view from controller? thx
There are two possibilities:
- When the button is clicked send an AJAX to call a controller action which will return a partial view containing a new
<input type="file" />
which upon success will be injected into the DOM - Directly inject into the DOM a new
<input type="file" />
when the button is clicked.
Here's an example. Suppose that you have the following markup:
<div id="files">
<input type="file" name="myfile" />
</div>
<a href="#" id="addfile">Add file</a>
and then using jquery:
$(function() {
$('#addfile').click(function() {
$('#files').append('<input type="file" name="myfile" />');
return false;
});
});
精彩评论