1

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

4
  • 1
    What do you mean by nothing happens ? Try run your debugger and see if you get into the Update action, or add a error to your ajax Commented Mar 28, 2017 at 10:12
  • What are you expecting to happen? The Action is empty Commented Mar 28, 2017 at 10:14
  • Your form does not include any form controls for id What are you expecting to pass to that parameter? Commented Mar 28, 2017 at 10:14
  • Also you have not shown what the method returns - does it return a JsonResult (you have specified dataType: "json",). And what do you want to do with the data you return - you success callback does not use the data Commented Mar 28, 2017 at 10:23

1 Answer 1

2

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)
{
}
Sign up to request clarification or add additional context in comments.

3 Comments

I've opened a new question (stackoverflow.com/questions/43071012/…). Your answer is the answer for this question :)
Ooops i'm late btw you got your answer no?
Yep ty! (#random words to fill space)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.