Mihai Labo
Mihai Labo

Reputation: 1082

Send model via jquery ajax call to dialog box

And i have this edit button :

 @Ajax.ActionLink(" ", "Edit", new { oid = item.memoOID }, new { id = "edit_" + item.memoOID })

I would like to populate the entity from the controller action "Edit" and send it to a dialog box defined below ( i want it to replace the new Domain.Model.memo() :

<div id="memoAddDialog" title="New Memo" style="display: none">
    @Html.Partial("~/Views/Pat/newMemoDialog.cshtml", new Domain.Model.memo())
</div>

With this popup :

function OpenMemoDialog() {
        $("#memoAddDialog").dialog("open");
    }

    $("#memoAddDialog").dialog({
        autoOpen: false,
        height: 575,
        width: 900,
        dialogClass: "positioning24"
    });

I just dont know how to pass the value to that partial view and need some pointers; can anyone help ?

Upvotes: 0

Views: 1569

Answers (2)

Shivkumar
Shivkumar

Reputation: 1903

Try this one

  //In View 
    @Ajax.ActionLink("AjaxLink", "Edit", new { oid = item.memoOID ,id = "edit_"+item.memoOID }, new AjaxOptions { UpdateTargetId = "memoAddDialog", HttpMethod = "Post",OnSuccess="Success" })

    <div id="memoAddDialog" title="New Memo" style="display: none">
    </div>

<script type="text/javascript">
function Success()
{
  //open your dialogbox here
   $("#memoAddDialog").dialog("open");
}

</script>

In Controller

[httpPost]
public ActionResult Edit(string oid , string id)
{
     //perform your functionality 

    return PartialView("~/Views/Patient/newMemoPatientDialog.cshtml", new Mavi.Domain.Model.memo());
}

NOTE: In Ajax.ActionLink you must provide UpdateTargetId where you result will appear on Page

Upvotes: 1

kows
kows

Reputation: 121

I would do something like this:

<a href="OpenMemoDialog('@(Url.Action("Edit", new oid = item.memoOID)')" />

with OpenMemoDialog as:

function OpenMemoDialog(url) {
        $("#memoAddDialog").dialog("open");
        $("#memoAddDialog").load(url);
    }

memoAddDialog is just an empty div & your Edit action should return the partial view.

Upvotes: 0

Related Questions