Javascript 添加选项以在ASP.NET MVC中使用bootbox.js的自定义对话框中选择表单控件
目前,我正在尝试显示一个对话框,当您单击按钮时,可以在其中删除工具架Javascript 添加选项以在ASP.NET MVC中使用bootbox.js的自定义对话框中选择表单控件,javascript,jquery,asp.net,asp.net-mvc,bootbox,Javascript,Jquery,Asp.net,Asp.net Mvc,Bootbox,目前,我正在尝试显示一个对话框,当您单击按钮时,可以在其中删除工具架 <button type="button" class="btn btn-default" id="deleteButton">Delete</button> 现在我的问题是:如何将shelfas选项添加到select元素 谢谢大家! 我解决了这个问题,我使用了StringBuilder来创建消息 @{ string deleteFormString = string.Empty; StringBui
<button type="button" class="btn btn-default" id="deleteButton">Delete</button>
现在我的问题是:如何将shelfas选项添加到select元素
谢谢大家! 我解决了这个问题,我使用了StringBuilder来创建消息
@{
string deleteFormString = string.Empty;
StringBuilder builder = new StringBuilder();
builder.Append(@"<div class=""row"">");
builder.Append("<div class=\"col-md-12\">");
builder.Append("<form class=\"form-horizontal\">");
builder.Append("<div class=\"form-group\">");
builder.Append("<label class=\"col-md-4 control-label\" for=\"shelfSelection\">Shelf</label>");
builder.Append("<div class=\"col-md-4\">");
builder.Append("<select id=\"shelfSelection\" id=\"shelfSelection\" class=\"form-control\">");
foreach (Shelf shelf in Model.Shelves)
{
string optionString = string.Format("<option value=\"{0}\">{0}</option>", shelf.Name);
builder.Append(optionString);
}
builder.Append("</select><span class=\"help-block\">Select the shelf to delete.</span> </div></div>");
builder.Append("<div class=\"form-group\">");
builder.Append("<label class=\"col-md-4 control-label\" for=\"deleteConfirmation\">Confirmation</label>");
builder.Append("<div class=\"col-md-4\"> <div class=\"checkbox\"> <label for=\"deleteConfirmation\">");
builder.Append("<input type=\"checkbox\" name=\"deleteConfirmation\" id=\"deleteConfirmation\">");
builder.Append("I confirm the deletion of the selected shelf.</label>");
builder.Append("</div></div> </div>");
builder.Append("</form> </div> </div>");
deleteFormString = builder.ToString();
}
@foreach (Shelf shelf in Model.Shelves)
{
string shelfName = @shelf.Name;
}
@{
string deleteFormString = string.Empty;
StringBuilder builder = new StringBuilder();
builder.Append(@"<div class=""row"">");
builder.Append("<div class=\"col-md-12\">");
builder.Append("<form class=\"form-horizontal\">");
builder.Append("<div class=\"form-group\">");
builder.Append("<label class=\"col-md-4 control-label\" for=\"shelfSelection\">Shelf</label>");
builder.Append("<div class=\"col-md-4\">");
builder.Append("<select id=\"shelfSelection\" id=\"shelfSelection\" class=\"form-control\">");
foreach (Shelf shelf in Model.Shelves)
{
string optionString = string.Format("<option value=\"{0}\">{0}</option>", shelf.Name);
builder.Append(optionString);
}
builder.Append("</select><span class=\"help-block\">Select the shelf to delete.</span> </div></div>");
builder.Append("<div class=\"form-group\">");
builder.Append("<label class=\"col-md-4 control-label\" for=\"deleteConfirmation\">Confirmation</label>");
builder.Append("<div class=\"col-md-4\"> <div class=\"checkbox\"> <label for=\"deleteConfirmation\">");
builder.Append("<input type=\"checkbox\" name=\"deleteConfirmation\" id=\"deleteConfirmation\">");
builder.Append("I confirm the deletion of the selected shelf.</label>");
builder.Append("</div></div> </div>");
builder.Append("</form> </div> </div>");
deleteFormString = builder.ToString();
}
$('#deleteButton').click(function () {
bootbox.dialog({
title: "Delete Shelf.",
message: '@Html.Raw(@deleteFormString)',
buttons: {
cancel: {
label: "Cancel",
className: "btn-default",
},
success: {
label: "Delete",
className: "btn-danger",
callback: function () {
var name = $('#name').val();
var answer = $("input[name='deleteConfirmation']:checked").val()
}
}
}
});