2

$ 我可以在管理部分 Plugin-->Import Product 中创建菜单项,但是当我单击它时,它给了我错误资源找不到。请帮助解决这个问题。我在下面附上了模型、视图、控制器和其他相关代码。

*************Model*************
namespace Nop.Plugin.Import.Product.Models
{
public class ImportProductModel
{        
    public string Button1 { get; set; }
}
 }

 **********Controller*************

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using Nop.Admin.Models.Catalog;
using Nop.Core.Domain.Catalog;
using Nop.Core.Infrastructure;
using Nop.Plugin.Import.Product.Models;
using Nop.Services.Catalog;
using ns_5OClock;

namespace Nop.Plugin.Import.Product.Controllers
{
class ImportProductController : Controller
{
    //
    // GET: /DisplayTime/

    public ActionResult Index(ImportProductModel model)
    {
        if (!String.IsNullOrEmpty(model.Button1))
        {
            CreateProduct();
        }

        return View();
    }

    //
  }
  }

   *************View (ImportProduct.cshtml) **********

   @{
   Layout = "";
   }
   @model Nop.Plugin.Import.Product.Models.ImportProductModel

   <table>
   <tr>
    <td>            
        <button title="Click to Create Products" 
        style="width:300px;height:60px"   name="Button1"></button>
    </td>
   </tr>
  </table>

    ***************Plugin (ImportProduct) **********************

   using System;
   using System.Collections.Generic;
   using System.Linq;
   using System.Text;
   using System.Threading.Tasks;
   using Nop.Core.Plugins;
   using Nop.Web.Framework.Web;

   namespace Nop.Plugin.Import.Product
   {
   public class ImportProduct : BasePlugin, IAdminMenuPlugin
   {
    public void BuildMenuItem(Telerik.Web.Mvc.UI.MenuItemBuilder menuItemBuilder)
    {
        menuItemBuilder.Text("Import Product");
        //menuItemBuilder.Url("/Plugins/ProductImport/Index");
        menuItemBuilder.Route("Plugin.Import.Product.ImportProduct");
     }
    }
    }

   **************Route Provider ****************

   using System.Web.Mvc;
   using System.Web.Routing;
   using Nop.Web.Framework.Mvc.Routes;

   namespace Nop.Plugin.Import.Product
   {
   public partial class RouteProvider : IRouteProvider
   {
    public void RegisterRoutes(RouteCollection routes)
    {
        routes.MapRoute("Plugin.Import.Product.ImportProduct",
             "Plugins/Import/ImportProduct",
             new { controller = "Import", action = "ImportProduct" },
             new[] { "Nop.Plugin.Import.Product.Controllers" }
        );

    }

    public int Priority
    {
        get
        {
            return 0;
        }
       }
       }
    }
4

1 回答 1

0

请查看您的路线登记表

routes.MapRoute("Plugin.Import.Product.ImportProduct",
      "Plugins/Import/ImportProduct",
      new { controller = "ImportProduct", action = "Index" },
      new[] { "Nop.Plugin.Import.Product.Controllers" }
);
于 2013-10-05T05:32:37.170 回答