Reputation: 53
I'm new with ASP.NET/Javascript and I'm having a little trouble with the implementation of simple CRUD operations using jQueryUI dialog form. This is my code:
<button class="update" id="@Model.id">Update</button>
<div id="dialog-form" title="Update">
<form>
<fieldset>
<input type="text" name="state" id="state">
<input type="text" name="note" id="note">
<input type="submit">
</fieldset>
</form>
</div>
<script>
$(function() {
var dialog,
state = $("#state"),
note = $("#note"),
id = this.id, //??
dialog = $("#dialog-form").dialog({
autoOpen: false,
height: 400,
width: 350,
modal: true,
buttons: {
"Ok": function() {
$.ajax({
type: "POST",
url: "@Url.Action("Update","Ticket")",
data: {
id: id,
state: state,
note: note
},
cache: false,
dataType: "json",
success: function(data) {
$("#dialog").dialog("close");
}
});
},
"Cancel": function() {
$(this).dialog("close");
}
}
});
$(".update").button().on("click", function() {
dialog.dialog("open");
});
});
</script>
Finally the Update
action in TicketController
:
public ActionResult Update(String id, String state, String note)
{
//do some stuff
}
However nothing happens and it doesn't get into the action. Any help is greatly appreciated
Upvotes: 1
Views: 975
Reputation: 5778
change your data
as below you need to pass value rather than the object by using .val()
state = $("#state").val(),
note = $("#note").val(),
id = "Pass anything you wants"
data: { 'id':id,'state':state,'note':note },
Decorate your action method with [HttpPost]
[HttpPost]
public ActionResult Update(String id, String state, String note)
{
}
Upvotes: 2