开发者

3 MVC2 forms one Jquery UI Dialog window

I have one partial view that I load up using Jquery UI Dialog window. This partial view has 3 forms that I initialize like so...

    <%using (Html.BeginForm("SearchByDemographic", "PatientACO", new { @PopID =   (int)ViewData["POPID"] }, FormMethod.Post, new { name = "addPat",  id = "DemoGraphID"  }))
    { %>

    <% using (Html.BeginForm("SearchByMRN", "PatientACO", new { @PopID = (int)ViewData["POPID"] }, FormMethod.Post, new { id = "MrnID" }))%>
  <%{

    <% using (Html.BeginForm("AddPatToPop", "PatientACO", new { @PopID = (int)ViewData["POPID"] }, FormMethod.Post, new { id = "AP2PID" }))%>
  <%{%>

As you can see, each of those forms refers to a different action on the same controller when a submit button is clicked... The first two actions return json Data via ajax to fill a drop down list. How can I write the Jquery UI dialog response correctly for this particular functionality. Keep in mind that I am almost a complete noob to Jquery. I had it working using SimpleDialog... I have so far struggled to add client side functionality to my websites by adding Jquery Libraries... Here is currently how I handle but开发者_StackOverflow中文版ton submission. I am pretty sure that this won't handle all the functionality I will need, why? I couldn't begin to tell you... Just a hunch though. I was testing the functionality on my visual studio setup, and I can't hit my second action (searchByDemographic)... So that is telling me that something is not set up quite correctly. Also, does anybody know any good Jquery Tutorials. I may need to pick that language up a bit. I definitely feel a little naked here attempting to add this functionality and having know idea how itr works...

    // jQuery Ajax-Post only works in repeatable manner when link that opens SimpleDialog can be placed 
    // outside the PartialView. Otherwise, calls to SimpleDialog fail on second and subsequent clicks. 
    // Need to use full postback in this case.
    $("#btnSubmit").live('click', function (event) {
        event.preventDefault();
        var $target = $(this).attr("name");
        var $url = $("#target").attr("action");
        $.ajax({
            url: $url,
            type: 'POST',
            data: $("#target").serialize(),
            success: function (response) {
                $.simpleDialog.close();
                $($target).html(response);
                $("#ajaxResult").hide().html('Record saved.').fadeIn(300, function () {
                    var e = this;
                    setTimeout(function () { $(e).fadeOut(400); }, 2000);
                });
            },
            error: function (xhr, status) {
                $("#ajaxResult").html(xhr.responseText).show();
                $.simpleDialog.close();
            }
        });
    });

If anybody has any kind of advice, links to good tutorials, or any examples of how to get this done, I would definitely appreciate it.


I was being an idiot here... Probably why I am likely to get canned. Oh well, better go out in a blaze of glory... But here is what I did to solve my problem. I went to the partial view and took a look at its ajax posting functions... Turns out I hard coded the addresses and that was why it wasn't working on the server...

     $(function () {
    $("#MRNSubmit").click(function (e) {
        e.preventDefault();
        var form = $("#MrnID");
        var srlzdform = form.serialize();
        var PopID = <% =PopID %>
        var options = [];
        var $url = $("#target").attr("action");
        var serializedForm = form.serialize();
        $.post('<%:Url.Action("SearchByMRN", "PatientACO")%>', srlzdform, function (data){
            options = $.map(data, function (item, i) {
                return "<option value=" + item.Value + ">" + item.Text + "</option>";
            });
            $("#PatientListToAdd").html(options.join(""));

        });
    });
});
$(function () {
    $("#DemoGraphSubmit").click(function (e) {
        e.preventDefault();
        var form = $("#DemoGraphID");
        var srlzdform = form.serialize();
        var PopID = <% =PopID %>
        var options = [];
        var $url = $("#target").attr("action");
        var serializedForm = form.serialize();
        $.post('<%:Url.Action("SearchByDemographic", "PatientACO")%>', srlzdform, function (data){
            options = $.map(data, function (item, i) {
                return "<option value=" + item.Value + ">" + item.Text + "</option>";
            });
            $("#PatientListToAdd").html(options.join(""));

        });
    });
});

It works perfectly fine now. Too little, too late,I am afraid.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜