如何从弹出窗口或部分视图提交后重定向到后期操作? [英] How to redirect to a post action after submit from popup or partial view?

查看:80
本文介绍了如何从弹出窗口或部分视图提交后重定向到后期操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张表如图所示我从表格中的按钮点击事件弹出窗口

点击这里获取表格IMG



点击该投诉按钮后,会出现以下代码:



代码如下:



上表的视图如img所示:



i have a table as shown in image bellow i get a popup on click event from a button in the table
CLICK HERE FOR TABLE IMG

After clicking on that complain button the following popup appears by following code:

the Code is as bellow:

the view for above table as shown in img as follows:

@model List<NomzyMVC.Models.MyRechargesModel>
@{
    ViewBag.Title = "My Recharges";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
          if (Model != null)
                        {
                        <table id="MyRechargesexample" class="table table-bordered table-hover">
                            <thead>
                                <tr id="0">
                                    <th>Sr No
                                    </th>
                                    <th>TransNo
                                    </th>
                                    <th>Type
                                    </th>
                                    <th>Category
                                    </th>
                                    <th>Company
                                    </th>
                                    <th>Product
                                    </th>
                                    <th>A/C
                                    </th>
                                    <th>Amount
                                    </th>
                                    <th>Discount
                                    </th>
                                    <th>LastBalance
                                    </th>
                                    <th>Description
                                    </th>
                                    <th>Date
                                    </th>
                                    <th></th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach (var item in Model)
                                {  
                                    <tr>
                                        <td>@Html.DisplayFor(modelItem => item.Userid)</td>
                                        <td>@Html.DisplayFor(modelItem => item.TransNo)</td>
                                        <td>@Html.DisplayFor(modelItem => item.RechargeType)</td>
                                        <td>@Html.DisplayFor(modelItem => item.RechargeCategory)</td>
                                        <td>@Html.DisplayFor(modelItem => item.CompanyName)</td>
                                        <td>@Html.DisplayFor(modelItem => item.ProductCode)</td>
                                        <td>@Html.DisplayFor(modelItem => item.Account)</td>
                                        <td>@Html.DisplayFor(modelItem => item.Value)</td>
                                        <td>@Html.DisplayFor(modelItem => item.Rcommission)</td>
                                        <td>@Html.DisplayFor(modelItem => item.RLastbalance)</td>
                                        <td>@Html.DisplayFor(modelItem => item.NomadicDescription)</td>
                                        <td>@Html.DisplayFor(modelItem => item.DT)</td>
                                        <td>
                                            @{
                                    decimal disc = Convert.ToDecimal(item.Rcommission);
                                    int calltransno = Convert.ToInt32(item.CallTransNo);
                                    if (calltransno == 0)
                                    {
                                        if (disc > 0)
                                        {
                                                <a id="btnRetailerComplain" title="@Html.DisplayFor(modelItem => item.TransNo)" class="complain">Complain</a>                                               
                                        }
                                        else
                                        {

                                        }
                                        // <button id="btnRetailerComplain"  title="@Html.DisplayFor(modelItem => item.TransNo)" type="button" class="btn btn-block btn-danger"> Complain</button>
                                    }
                                    else
                                    {
                                                <a id="btnRetaiComplain" title="@Html.DisplayFor(modelItem => item.TransNo)" class="showcomplain">ShowComp</a>
                                        // <button id="btnRetaiComplain"  title="@Html.DisplayFor(modelItem => item.TransNo)" type="button" class="btn btn-block btn-warning" style="font-size:small;padding-left:3px;"> Show Complain</button>
                                    }
                                            }

                                        </td>

                                    </tr>
                          
                            
                                }
                            </tbody>
                        </table>
                        }





和POPUP的视图如下所示:Bellow:





And the View For POPUP is as shown Bellow:

$("#MyRechargesexample tbody tr td a").click(function () {
    var transno = $(this).attr('title');
    var buttontype = $(this).attr('class');
    var datefrom = $("#DateFrom").val();
    var dateto = $("#DateTo").val();
    alert(buttontype);
    if (buttontype == "complain") {
        $.ajax({
            url: "/Retailer/_GetComplain",
            type: "GET",
            data: { TransNo: transno, Type: buttontype, DateFrom: datefrom, DateTo: dateto },
            success: function (data) {
                // alert(data);
                var dialog = new BootstrapDialog({
                    type: 'type-primary',
                    title: '<h4>  Complain</h4>',
                    message: data
});
                dialog.realize();
                dialog.getModalDialog().css("width", "500px");
                dialog.getModalDialog().css("height", "400px");
                dialog.open();
            }
        });
    }
    else {
        $.ajax({
            url: "/Retailer/_GetComplain",
            type: "GET",
            data: { TransNo: transno, Type: buttontype, DateFrom: datefrom, DateTo: dateto },
            success: function (data) {
                // alert(data);
                var dialog = new BootstrapDialog({
                    type: 'type-primary',
                    title: '<h4>  Complain Details</h4>',
                    message: data
                });
                dialog.realize();
                dialog.getModalFooter().hide();
                dialog.getModalDialog().css("width", "500px");
                dialog.getModalDialog().css("height", "400px");
                dialog.open();
            }
        });
    }
});





和控制器如下:





and the controller is as follows:

[HttpGet]
        public PartialViewResult _GetComplain(string TransNo, string Type)
        {
            if (Type == "complain")
            {
                TempData["type"] = "WriteComplain";
                var query = (from c in NMSDC.DataSends
                             where c.DSID == Convert.ToInt32(TransNo)
                             select c).SingleOrDefault();

                GetComplainModel gt = new GetComplainModel();
                gt.UserID = query.UserID;
                gt.Number = query.account;
                gt.Amount = query.value.ToString();
                gt.Company = query.CompanyName;
                gt.Transno = query.DSID.ToString();
                gt.DT = query.DT;

                return PartialView(gt);
            }
            else
            {
                TempData["type"] = "ShowComplain";
                var query = (from CL in NMSDC.CallCenterLogs
                             join SC in NMSDC.SubCategories on CL.SCID equals SC.SCID
                             where CL.IsDeleted == false && CL.Status == false && CL.TransactionNo == TransNo
                             orderby CL.DT descending
                             select new
                             {
                                 CL.QID,
                                 CL.Status,
                                 CL.Note,
                                 CL.CustID,
                                 CL.UserID,
                                 CL.TransactionNo,
                                 CL.Amount,
                                 CL.CompanyName,
                                 CL.account,
                                 CL.AddNote,
                                 CL.DT,
                                 CL.PDID,
                                 SC.SubType,
                             }).SingleOrDefault();

                GetComplainModel gt = new GetComplainModel();
                gt.UserID = query.UserID;
                gt.Number = query.account.ToString();
                gt.Amount = query.Amount.ToString();
                gt.Company = query.CompanyName;
                gt.Transno = query.TransactionNo.ToString();
                gt.Category = query.SubType;
                gt.Note = query.Note;
                gt.DT = (DateTime)query.DT;
                gt.ComplainNo = query.QID.ToString();
                gt.CallCenterAC = query.CustID;
                return PartialView(gt);
            }

        }





,弹出窗口如下:



点击这里获取POUP IMG



我把部分视图作为易于处理的GET和POST方法,所以请在问题中查看它,getcomplain的视图如下:





and the popup appears as such :

Click HERE FOR POUP IMG

i took the partial view as its easy to handle GET and POST methods so please look at it in the question and the view for getcomplain is as follows:

@model NomzyMVC.Models.GetComplainModel
@using (Html.BeginForm())
{
    if (TempData["type"] == "WriteComplain")
    {
    <div id="test" class="row" style="margin-removed -50px !important; margin-removed -50px !important">
        <div class="col-md-12">
            Retailer :       <span>@Html.DisplayFor(model => model.UserID) </span>

            Amount :        <span>@Html.DisplayFor(model => model.Amount) </span>
            @Html.TextBox("Amount", null, new { @style = "display:none" })
            Transno :        <span>@Html.DisplayFor(model => model.Transno) </span>
            @Html.TextBox("Transno", null, new { @style = "display:none" })
            Number :        <span>@Html.DisplayFor(model => model.Number) </span>
            @Html.TextBox("Number", null, new { @style = "display:none" })
            Company :       <span>@Html.DisplayFor(model => model.Company)</span>
            @Html.TextBox("Company", null, new { @style = "display:none" })
            Category :       @Html.DropDownList("Category", new List<SelectListItem> {
                                   new SelectListItem{Text="Bal Deduct",Value="7"},
                                   new SelectListItem{Text="Balance Not Received",Value="13"}
                                   }, new { @style = "width:50%" })

            Note :              @Html.TextBox("Note", null, new { @style = "width:50%", placeholder = "Enter Your Note" })
            @Html.TextBox("DT", null, new { @style = "display:none" })
        </div>
        <div class="col-md-12">
            <div class="col-md-5">
                <button type="submit" id="btnWriteComplain" class="btn btn-block btn-warning" value="WriteComplain" name="Command" style="width: 100%;">Submit</button>
            </div>
            @*<div class="col-md-5" style="margin-removed -20px;">
                <button type="button" id="btnComplaincancel" class="btn btn-block btn-default" value="Clear" style="width: 100%;">Cancel</button>
            </div>*@
        </div>
    </div>
    }
    else
    {
    <div id="showcomp" class="row" style="margin-removed -50px !important; margin-removed -50px !important">
        <div class="col-md-12">
            Complain No  :      <span>@Html.DisplayFor(model => model.ComplainNo)</span>

            UserID               :      <span>@Html.DisplayFor(model => model.UserID) </span>

            Amount            :       <span>@Html.DisplayFor(model => model.Amount) </span>

            Transno            :      <span>@Html.DisplayFor(model => model.Transno) </span>

            Number            :      <span>@Html.DisplayFor(model => model.Number) </span>

            Company         :     <span>@Html.DisplayFor(model => model.Company)</span>

            Complain By  :      <span>@Html.DisplayFor(model => model.CallCenterAC) </span>

            Category          :     @Html.DisplayFor(model => model.Category)

            Note                   :    @Html.DisplayFor(model => model.Note)

        </div>
    </div>
    }
}





and after clicking on that submit button of popup the following code executes :



the controller code is as follows:





and after clicking on that submit button of popup the following code executes :

the controller code is as follows:

[HttpPost]
        public PartialViewResult _GetComplain(string Command, string Number, string Amount, string TransNo, string Company, string Category, string Note, DateTime DT)
        {
            if (Command == "WriteComplain")
            {
                var result = (from c in NMSDC.CallCenterLogs
                              where c.TransactionNo == TransNo
                              //&& c.PDID == 3 && c.SCID == Category
                              select new
                              {
                                  c.TransactionNo,
                                  c.PDID,
                                  c.SCID
                              }).ToList();
                if (result.Count == 0)
                {
                    if (DT >= System.DateTime.Now.AddDays(-7))
                    {
                        // NMSDC.USP_Insert_CallCenterLog(Session["UserID"].ToString(), Session["UserID"].ToString(), Number, Convert.ToString(Amount), Convert.ToString(TransNo), Company, 3, SCID, Note, null, "Retailer");
                        //Response.RedirectToRoute("Select", "Search", TempData["Dt1"].ToString(), TempData["Dt2"].ToString());
//---THE PROBLEM IS HERE I AM REDIRECTING IT THE PAGE BUT IT WONT REDIRECT AND I MIGHT BE SHOWING POPUP using WRONG METHOD------------------- //  
                         RetailerController rec = new RetailerController();
                        rec.MyRecharges("Select", "Search", TempData["Dt1"].ToString(), TempData["Dt2"].ToString());
                        ComplainRedirct();
                        this.MyRecharges("Select", "Search", TempData["Dt1"].ToString(), TempData["Dt2"].ToString());
                    }
                    else
                    {
                        // string msg = "You can not write complain 1 week old.";
                        ComplainRedirct();
                    }
                }
                else
                {
                    string msg = "You have already registered complain for this transaction.";
                    ComplainRedirct();
                }
            }
            return PartialView();
        }





THE PROBLEM IS AFTER THIS I WANT THE POPUP TO CLOSE AND THE BEHIND SEARCH SHOULD REMAIN INTACT BUT IT ISN’T THE CASE , I THink that my showing of popup method is wrong pls help me on this, bcz after clicking on submit the popup closes but i redirect to the same page i.e MyRecharge but all the search is gone and i have to search all to gather pls pls help on this.



THE PROBLEM IS AFTER THIS I WANT THE POPUP TO CLOSE AND THE BEHIND SEARCH SHOULD REMAIN INTACT BUT IT ISN'T THE CASE , I THink that my showing of popup method is wrong pls help me on this, bcz after clicking on submit the popup closes but i redirect to the same page i.e MyRecharge but all the search is gone and i have to search all to gather pls pls help on this.

推荐答案

(\"#MyRechargesexample tbody tr td a\").click(function () {
var transno =
("#MyRechargesexample tbody tr td a").click(function () { var transno =


(this).attr('title');
var buttontype =
(this).attr('title'); var buttontype =


(this).attr('< span class=\"code-string\">class');
var datefrom =
(this).attr('class'); var datefrom =


这篇关于如何从弹出窗口或部分视图提交后重定向到后期操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆