I have a web project that I want to create text box dynamically and a Button for every text box that upload a file and I have below code, my problem is I get null when check files in my controllers, I think I must put a array file to get but I don't know why it doesn't work
Thank you
my cshtml
<h2>اضافه کردن سؤال جدید</h2>
@using (Html.BeginForm("AddNewQuestion", "BestDestinationResult", FormMethod.Post,
new { enctype = "multipart/form-data" }))
{
<input id="btnAdd" type="button" value="اضافه کردن پاسخ" onclick="AddTextBox()" />
<br />
<br />
<div id="TextBoxContainer">
<!--Textboxes will be added here -->
</div>
<br />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
function GetDynamicTextBox(value) {
var div = $("<div />");
var textBox = $("<input />").attr("type", "textbox").attr("name", "answers");
textBox.val(value);
div.append(textBox);
var button = $("<input />").attr("type", "file").attr("files", "files");
button.attr("onclick", "ChooseImage(this)");
div.append(button);
return div;
}
function AddTextBox() {
var div = GetDynamicTextBox("");
$("#TextBoxContainer").append(div);
}
function ChooseImage(button) {
$(button).
}
$(function () {
var values = eval('@Html.Raw(ViewBag.Values)');
if (values != null) {
$("#TextBoxContainer").html("");
$(values).each(function () {
$("#TextBoxContainer").append(GetDynamicTextBox(this));
});
}
});
</script>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="ذخیره" class="btn btn-success" />
</div>
</div>
</div>
}
my controller:
public ActionResult AddNewQuestion(Models.BestDestinationAddNewQuestionViewModel que, HttpPostedFileBase[] files, string[] answers)
{
// my code
}