NopCommerce -页面导航问题与Telerik-Grid

本文关键字:Telerik-Grid 问题 导航 -页 NopCommerce | 更新日期: 2023-09-27 17:54:04

我使用的是nopCommerce。我已经使用teleik -grid将数据绑定到表中,并且数据绑定成功。我已经为编辑操作创建了名为"EditContact"的方法。但当我点击编辑链接重定向页面名为"_createorupdateccontact。cshtml",我得到"Page not found"页。

远程网格代码:

@(Html.Telerik().Grid<AddressModel>()
                .Name("vendors-grid")
                .Columns(columns =>
                {
                    columns.Bound(x => x.CountryName)
                        .Width(200).Centered();
                    columns.Bound(x => x.FirstName)
                        .Width(200).Centered();
                    columns.Bound(x => x.LastName)
                        .Width(200).Centered();
                    columns.Bound(x => x.Title)
                        .Width(200).Centered();
                    columns.Bound(x => x.Email)
                        .Width(200).Centered();
                    columns.Bound(x => x.PhoneNumber)
                        .Width(200).Centered();
                    columns.Bound(x => x.Address1)
                    .Width(200).Centered();
                    columns.Bound(x => x.Id)
                        .Width(200)
                        .Centered()
                        .Template(x => Html.ActionLink(T("Admin.Common.Edit").Text, "Edit", new { id = x.Id }))
                        .ClientTemplate("<a href='"EditContact/<#= Id #>'">" + T("Admin.Common.Edit").Text + "</a>")
                        .Title(T("Admin.Common.Edit").Text);
                    columns.Bound(x => x.Id)
                    .Template(x => Html.ActionLink(T("Admin.Common.Delete").Text, "Delete", new { id = x.Id }))
                    .ClientTemplate("<a href='"Delete/<#= Id #>'">" + T("Admin.Common.Delete").Text + "</a>")
                    .Centered().Width(200)
                    .HeaderTemplate(T("Admin.Common.Delete").Text);
                })
                .Pageable(settings => settings.PageSize(gridPageSize).Position(GridPagerPosition.Both))
                .DataBinding(dataBinding => dataBinding.Ajax().Select("ListContacts", "VendorDetails",new { vendorId = Model.Id }))
                .EnableCustomBinding(true))

EditContact。cshtml代码

@model AddressModel
@using (Html.BeginForm())
{
<div class="section-header">
   <div class="options">
        <input type="submit" name="save" class="t-button" value="@T("Admin.Common.Save")" />
        <input type="submit" name="save-continue" class="t-button" value="@T("Admin.Common.SaveContinue")" />
    </div>
</div>
@Html.Partial("_CreateOrUpdateContact", Model)
}
@Html.DeleteConfirmation("vendor-delete")

VendorDetailsController Methods:

[HttpPost, GridAction(EnableCustomBinding = true)]
    public ActionResult ListContacts(int vendorId,GridCommand command)
    {
        if (!_permissionService.Authorize(StandardPermissionProvider.ManageVendors))
            return AccessDeniedView();
        var Addresses = _addressService.GetVendorAddresses(vendorId);
        var gridModel = new GridModel<AddressModel>
        {
            Data = Addresses.Select(x =>
            {
                var a = new AddressModel();
                PrepareAddressModel(a, x, false);
                return a;
            }),
            Total = Addresses.Count,
        };
        return new JsonResult
        {
            Data = gridModel
        };
    }  
    // edit vendor contact
    public ActionResult EditContact(int id)
    {
        if (!_permissionService.Authorize(StandardPermissionProvider.ManageVendors))
            return AccessDeniedView();
        var address = _addressService.GetAddressById(id);
        int vendorId = _vendorContactService.GetVendorIdByAddressId(address.Id);
        if (address == null)
            //No Address found
            return RedirectToAction("Edit", new { id = vendorId });
        var model = new AddressModel();
        model.VendorId = vendorId;
        //Ordering Method
        model.AvailableCountries.Add(new SelectListItem() { Text = "-- Select --", Value = "0" });
        foreach (var c in _countryService.GetAllCountries(true))
            model.AvailableCountries.Add(new SelectListItem() { Text = c.Name, Value = c.Id.ToString() });
        PrepareAddressModel(model, address, false);
        return View(model);
    }

我做错了什么吗?
我如何从telerik网格重定向-编辑链接到_createorupdateccontact。cshtml页面?

NopCommerce -页面导航问题与Telerik-Grid

请检查是否" _createorupdateccontact。"EditContact.cshtml"与"EditContact.cshtml"位于同一位置。我建议您调试代码。在"public ActionResult EditContact(int id)"处设置一个断点,然后检查从网格中单击编辑链接后是否命中了调试点。如果没有命中,则可能是路由有问题。

如果你能提供你发现的错误的屏幕截图就更好了

您可以在telerik-grid中查看路线

columns.Bound(x => x.Id)
       .Width(200)
       .Centered()
       .Template(x => Html.ActionLink(T("Admin.Common.Edit").Text, "Edit", new { id = x.Id }))
       .ClientTemplate("<a href='"EditContact/<#= Id #>'">" + T("Admin.Common.Edit").Text + "</a>")
       .Title(T("Admin.Common.Edit").Text);

当我认为路线有问题时,我应该这样做

columns.Bound(x => x.Id)
       .Width(200)
       .Centered()
       .Template(x => Html.ActionLink(T("Admin.Common.Edit").Text, "EditContact", new { id = x.Id }))
       .ClientTemplate("<a href='"EditContact/<#= Id #>'">" + T("Admin.Common.Edit").Text + "</a>")
       .Title(T("Admin.Common.Edit").Text);