为什么具有两个参数的简单方法在 MVC 中不起作用 ASP.NET?



我的控制器:

public class AjaxController : Controller
{
private readonly IGenerationUnitMobileService _generationUnitMobileService;
public AjaxController(IGenerationUnitMobileService generationUnitMobileService)
{
_generationUnitMobileService = generationUnitMobileService;
}
public IActionResult MobileExistToAnotherGenerationUnit(String mobile, long generation_unit_id)
{
//ViewBag.Result =  _generationUnitMobileService.MobileExistToAnotherGenerationUnit(mobile,generationUnitId);
return View();
}
}

我的视图文件非常简单:

@model PgcgSms.WebSite.Models.GenerationUnitMobileViewModel
@{
Layout = "~/Views/Shared/_Ajax.cshtml";
}
@ViewBag.Result

这太直截了当了。但是当我浏览时:http://localhost:57216/Ajax/MobileExistToAnotherGenerationUnit/01719393045/1

我收到以下错误消息:

This localhost page can’t be found
No webpage was found for the web address: http://localhost:57216/Ajax/MobileExistToAnotherGenerationUnit/01719393045/1
Search Google for localhost 57216 Ajax Mobile Exist To Another Generation Unit 01719393045
HTTP ERROR 404

我多次检查了视图文件和拼写。我的代码有什么问题?

在 RouteConfig.cs 文件中,您必须指定默认路由。 例如:

公共类路由配置 { 公共静态无效 注册路由(路由收集路由( { 路线。IgnoreRoute("{resource}.axd/{*pathInfo}"(;

routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "AjaxController", action = "MobileExistToAnotherGenerationUnit", id = UrlParameter.Optional }
);
}
}

最新更新