错误:jquery.min.js返回500个内部服务器错误

时间:2019-03-25 10:17:43

标签: javascript jquery asp.net-mvc-4 bootstrap-modal

我在带有实体框架6.0的asp.net MVC 4中创建一个Web应用程序。 在其中创建数据的详细信息(列表)。在列表顶部,单击一个按钮添加一些数据。单击编辑按钮后,表单将在引导模式弹出窗口中打开。它工作正常。在详细信息页面中,每一行均已编辑,并且该用户的删除按钮可以删除该记录。

现在,单击编辑按钮时,将打开包含数据的弹出窗口。但是,现在这不能正常工作。它在jquery.min.js文件中给我一个错误 500 Internal server error。

在这里,我放了一些代码片段,以便更好地理解。

这是我的CurrencyDetail页面

@model IEnumerable<RedICMVC.Models.Currency>

@{
    ViewBag.Title = "CurrencyDetail";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="card">
    <div class="card-header card-header-primary card-header-icon">
        <div class="card-icon">
            <i class="material-icons">assignment</i>
        </div>
        <h4 class="card-title">Currency Details</h4>
        <p style="float:right">
            <a class="btn btn-primary" onclick="AddEdit()">
                <i class="material-icons">add</i>Add Currency
            </a>
        </p>
    </div>
    <div class="card-body">
        <div class="material-datatables">
            <table id="datatables" class="table table-striped table-bordered dt-responsive table-hover text-center" cellspacing="0" width="100%" style="width:100%">
                <thead>
                    <tr>
                        <th></th>
                        <th>
                            @Html.DisplayNameFor(model => model.SR)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.Currency1)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.Cur_Name)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.MainCurrency)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.CoinCurrency)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.ExRate)
                        </th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var item in Model)
                    {
                        <tr>
                            <td nowrap>
                                <a href="@Url.Action("GetRecordFromId","Currency", new { id = item.SR })" class="commanId" Value="@item.SR">
                                    <i class="material-icons icon_size">edit</i>
                                </a>|
                                <a href="#" data-toggle="modal" data-id="@item.SR" data-target="#confirmDelete" data-title="Delete Currency" data-message="Are you sure you want to delete this currency ?">
                                    <i class="material-icons icon_size">delete</i>
                                </a>
                            </td>
                            <td>
                                @Html.DisplayFor(modelItem => item.SR)
                            </td>
                            <td>
                                @Html.DisplayFor(modelItem => item.Currency1)
                            </td>
                            <td>
                                @Html.DisplayFor(modelItem => item.Cur_Name)
                            </td>
                            <td>
                                @Html.DisplayFor(modelItem => item.MainCurrency)
                            </td>
                            <td>
                                @Html.DisplayFor(modelItem => item.CoinCurrency)
                            </td>
                            <td>
                                @Html.DisplayFor(modelItem => item.ExRate)
                            </td>
                        </tr>
                    }
                </tbody>
            </table>
        </div>
    </div>
</div>
@Html.Partial("DialogBox", "Home")
<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="model1" class="modal fade">
    <div class="modal-dialog modal-md">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                @*<h4 class="modal-title">Add Unit</h4>*@
            </div>
            <div class="modal-body" id="modelBody">
            </div>
        </div>
    </div>
</div>
@section scripts{
    <script>
        var AddEdit = function (SR) {
            var url = "/Currency/AddCurrency?id=" + SR;
            $("#modelBody").load(url, function () {
                $("#model1").modal("show");
            })
        }
        $('.commanId').click(function () {
            debugger;
            var id = $(this).val();
            $.get("/Currency/GetRecordFromId?id=" + id, function (data, status) {
                debugger;
                var url = "/Currency/GetRecordFromId?id=" + id;
                $("#modelBody").load(url, function () {
                    $("#model1").modal("show");
                })
            });
        });

    </script>
}

这是我的AddCurrency页面

@model RedICMVC.Models.SpCurrency

@{
    ViewBag.Title = "AddCurrency";
    Layout = null;
}
<!DOCTYPE html>
<div class="card">
    <div class="card-header card-header-rose card-header-icon">
        <div class="card-icon">
            <i class="material-icons">details</i>
        </div>
        <h4 class="card-title">Add Currency</h4>
    </div>
    <div class="card-body">
        @using (Html.BeginForm("AddCurrency", "Currency", FormMethod.Post, new { enctype = "multipart/form-data" }))
        {
            @Html.AntiForgeryToken()
            @Html.ValidationSummary(true, "", new { @class = "text-danger" })
            <div class="row justify-content-center">
                <div class="col-lg-10">
                    <div class="form-group require">
                        @Html.EditorFor(model => model.Currency, new { htmlAttributes = new { @class = "form-control", @placeholder = "Currency" } })
                        @Html.ValidationMessageFor(model => model.Currency, "", new { @class = "text-danger" })
                    </div>
                </div>
                <div class="col-lg-10">
                    <div class="form-group">
                        @Html.EditorFor(model => model.Cur_Name, new { htmlAttributes = new { @class = "form-control", @placeholder = "Currency Name" } })
                        @Html.ValidationMessageFor(model => model.Cur_Name, "", new { @class = "text-danger" })
                    </div>
                </div>
                <div class="col-lg-10">
                    <div class="form-group">
                        @Html.EditorFor(model => model.MainCurrency, new { htmlAttributes = new { @class = "form-control", @placeholder = "Main Currency" } })
                        @Html.ValidationMessageFor(model => model.MainCurrency, "", new { @class = "text-danger" })
                    </div>
                </div>
                <div class="col-lg-10">
                    <div class="form-group">
                        @Html.EditorFor(model => model.CoinCurrency, new { htmlAttributes = new { @class = "form-control", @placeholder = "Coin Currency" } })
                        @Html.ValidationMessageFor(model => model.CoinCurrency, "", new { @class = "text-danger" })
                    </div>
                </div>
                <div class="col-lg-10">
                    <div class="form-group">
                        @Html.EditorFor(model => model.ExRate, new { htmlAttributes = new { @class = "form-control", @placeholder = "Excext Rate" } })
                        @Html.ValidationMessageFor(model => model.ExRate, "", new { @class = "text-danger" })
                    </div>
                </div>
                <div class="card-footer">
                    <div class="card-footer">
                        <input type="submit" class="btn btn-finish btn-fill btn-rose btn-wd" name="Save" value="Save">
                        <input type="reset" class="btn btn-finish btn-fill btn-danger btn-wd" name="reset" value="Reset">
                    </div>
                </div>
            </div>
        }
    </div>
</div>
@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

这是我的控制者

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RedICMVC.Models;
using RedICMVC.Common.Toaster;
using System.Data.SqlClient;

namespace RedICMVC.Controllers.Masters
{
    public class CurrencyController : Controller
    {
        protected RedICMVCDBEntities Db = new RedICMVCDBEntities();
        // GET: Currency
        public ActionResult CurrencyDetail()
        {
            var sprecult = Db.Currencies.ToList();
            return View(sprecult);
        }
        public ActionResult AddCurrency()
        {
            return View();
        }
        [HttpPost]
        public ActionResult AddCurrency(SpCurrency cr)
        {
            if (cr.SR == 0)
            {
                var spresult = Db.Sp_Currency_Insert(cr.Currency, cr.Cur_Name, cr.MainCurrency, cr.CoinCurrency, cr.ExRate);
                if (spresult == 1 || spresult == -1)
                {
                    this.AddToastMessage("Success!!", "Currency Added Succesfully!!", ToastType.Success);
                }
                else
                {
                    this.AddToastMessage("Error!!", "Something Went To Wrong.!! Please try again.", ToastType.Error);
                }
                ModelState.Clear();
                return RedirectToAction("CurrencyDetail");
            }
            else
            {
                var spresult = Db.Sp_Currency_Update(cr.SR, cr.Currency, cr.Cur_Name, cr.MainCurrency, cr.CoinCurrency, cr.Symbol, cr.ExRate);
                if(spresult==1||spresult==-1)
                {
                    this.AddToastMessage("Success!!", "Currency Updated Succesfully!!", ToastType.Success);
                }
                else
                {
                    this.AddToastMessage("Error!!", "Something Went To Wrong.!! Please try again.", ToastType.Error);
                }
                ModelState.Clear();
                return RedirectToAction("CurrencyDetail");
            }
            return View();
        }

        [HttpGet]
        public ActionResult GetRecordFromId(int id)
        {
            var idParam = new SqlParameter
            {
                ParameterName = "SR",
                Value = id
            };
            var courseList = Db.Database.SqlQuery<SpCurrency>("exec sp_Currency_Get @SR", idParam).FirstOrDefault<SpCurrency>();
            return View("AddCurrency", courseList);
        }

        public ActionResult DeleteConfirmed(int id)
        {
            var spresult = Db.sp_Currency_Delete(id);
            if (spresult == 1 || spresult == -1)
            {
                this.AddToastMessage("Success", "Record deleted successfully", ToastType.Success);
            }
            else
            {
                this.AddToastMessage("Error", "Something went wrong", ToastType.Error);
            }
            return Content("Test");
        }
    }
}

这是输出的图像,同时显示(错误和我想要的输出) Output image
请,有人可以给我解决方案吗? 预先谢谢你。

0 个答案:

没有答案