【发布时间】:2012-03-23 19:07:34
【问题描述】:
我正在尝试将按钮的值传递给模式对话框。我的按钮事件如下所示:
//Dialog Function=============================================================
//declaring the function
$(function () {
$('#dialog').dialog({
autoOpen: false,
hide: 'fade',
show: 'fade',
width: 350,
height: 270,
resizable: false,
modal: true,
dialogClass: 'dialog',
open: function (event, ui) {
$(this).load('@Url.Action("AddFiles", "ProjectDetails")');
}
});
});
//Showing the dialog when one of the 3 buttons is clicked.
$("button[name='Add']").click(function () {
$('#type').val($(this).val());
$('#dialog').dialog('open');
});
//=========================================================================
我将值传递给我的模态 div 中的隐藏字段:
@Html.Hidden("type")
所以我需要把它变成一个 HiddenFor 并且为此我需要传递一个模型视图类 在我的 AddFiles 方法中
public ActionResult AddFiles()
{
return View();
}
这将是我的模型:
public class FileViewModel
{
public string Name { get; set; }
public string type { get; set; }
public string comments { get; set; }
}
但我不知道如何将按钮的值分配给我将创建的模型(模型将具有字符串类型属性)有没有办法做到这一点,或者我别无选择,可以使用独立隐藏场地?
【问题讨论】:
标签: javascript jquery asp.net-mvc-3 dialog modal-dialog