Reputation: 593
I'm trying to pass the value of a button to a modal dialog. My button event looks like this:
//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');
});
//=========================================================================
Iim passing the value to a hidden field in my modal div:
@Html.Hidden("type")
So what I need is to turn it into a HiddenFor and for that i need to pass a modelview class in my AddFiles method
public ActionResult AddFiles()
{
return View();
}
This would be my model:
public class FileViewModel
{
public string Name { get; set; }
public string type { get; set; }
public string comments { get; set; }
}
But I dont know how to assing the value of the button to the model that i would create (the model would have a string type attribute) Is there way to do this or I have no choice that to work with the independent hidden field?
Upvotes: 0
Views: 1737
Reputation: 440
I ran into the same thing and there is a simple solution. You need to pass the id in and THEN open the dialog. Here is an example in php. I'm doing the same in mvc so as soon as I have the syntax I'll post it.
Here's the link. http://groups.google.com/group/jquery-en/browse_thread/thread/13a3a580b4128d3d
Also, I forgot to mention that if you're passing your data to the model you'll need a constructor to create an instance of that class, ie:
var DataBuilderList = new List<FileViewModel>();
DataBuilderList.Add(new FileViewModel{ name = "thename", type = "thetype", comments = "comments" });
You'll need to call a method from the controller that will do that after it has been passed into the action.
If I'm wrong or have any comments let me know. goodluck.'
btw, it is the same syntax as it is jquery:
open: function () { $(this).load('ProjectDetails/AddFiles', { : id }), function () { }
}
you'll need to add a parameter to your action result for the button name, but that should work for what I think you're doing.
Upvotes: 1