开发者

MVC-generating control on view from controller

开发者 https://www.devze.com 2023-02-03 14:55 出处:网络
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?

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:

  1. 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
  2. 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;
    });
});
0

精彩评论

暂无评论...
验证码 换一张
取 消