MVC 4 - 在使用jquery单击按钮后努力获得刷新页面

时间:2014-02-25 16:58:20

标签: jquery asp.net-mvc asp.net-mvc-4

我需要你的帮助。我主要编写的代码似乎工作得很好,但我正在努力的一件事是点击重新提交按钮后获取刷新页面。我不想手动刷新它。 RefreshPage方法不起作用。 Jquery看起来效果不佳。不确定问题出在哪里。看看下面的代码,我做错了什么?希望你能帮忙解决它。我知道这是一件小事,但我不知道哪里可能存在问题。我正在使用ASP.NET MVC 4

HomeController中:

[HttpPost]
    public ActionResult Resubmit(Guid id, string vendorcode, string reason)
    {
        .
        .
        .

       _client.Resubmit(new Resubmission
                    {
                        Id = id,
                        Reason = reason,
                        VendorName = vendorcode,
                        UserId = 2
                    }).ToString());

        .
        .
        .

        return RedirectToAction("RefreshPage");
    }

    public ActionResult RefreshPage()
    {

        transmissions = TransmissionService.LoadTransmissions(Guid.Empty, string.Empty, null, null, string.Empty, "Error");

        return PartialView(transmissions);
    }

查看:索引

<div id="mainframeContens"> </div>

@{
WebGrid grid = new WebGrid(Model, rowsPerPage: 100);
 }
 <div id="gridcontent" >
@grid.GetHtml(
    htmlAttributes: new { id = "grid" },
    columns: grid.Columns(
        grid.Column(columnName: "ConvertedId", header: "Transmission ID", style: "colId", format: (item) => string.IsNullOrEmpty(item.ConvertedId)?string.Empty:item.ConvertedId),
        grid.Column(columnName: "Status", header: "Status", style: "colStatus", format: (item) => string.IsNullOrEmpty(item.Status)?string.Empty:item.Status),
        grid.Column(columnName: "Component", header: "Component", style: "colComponent", format: (item) => string.IsNullOrEmpty(item.Component)?string.Empty:item.Component),
        grid.Column(columnName: "Reason", header: "Reason", format: (item) => Html.TextBox("Reason", (object)item.Reason), canSort: false, style:"colReason"),
        grid.Column(style:"colResubmit",format: @<text><input type="button" id="Resubmit" value="Resubmit" data-url="@Url.Action("RefreshPage") />
                                                    <input type="hidden" id="txtID" value="@item.Id"/>
                                                    <input type="hidden" id="txtVendorcode" value="@item.VendorCode"/></text>)
        ))

的Javascript

//Here I am trying to get refresh page after resubmit but it is not working. I have to refresh it manually
<script type="text/javascript">
$(function () {
    $('#Resubmit').click(function (e) {
        e.preventdefault();
        var url = $(this).data(url);
        $('#mainframeContens').load(url);
    });
});


$(function () {
    $(':button').click(function () {
        if (reasonstr.length > 1000) {
            $('#tempMessage').html('');
            $('#h1ErrorMessage').html("Reason cannot be more than 1000 characters");
            return;
        } else {
            var asciiToMatch = new RegExp("^[\x20-\x7E\\r\\n\\t]+$");
            var ismatch = asciiToMatch.test(reasonstr);

            if (ismatch) {
            $.ajax({
                url: '@Url.Action("Resubmit")',
                type: 'POST',
                    data: { id: parent.find('#txtID').val(), vendorcode: parent.find('#txtVendorcode').val(), reason: reasonstr },
                success: function (data) {
                    window.location.href = data.Url;
                }
            });
        }

    });
});

0 个答案:

没有答案