ASP.NET MVC 3应用程序无法正常工作

时间:2012-01-16 11:43:19

标签: c# asp.net-mvc

我传递了像“http://localhost:6384/Name/4:”这样的网址但是这会出错。

控制器方法:

//
// GET: /Name/5
        public string SetName(int id)
        {
            return "You entered: " + id;
        }

错误:

Server Error in '/' Application.

HTTP Error 400 - Bad Request.

Version Information: ASP.NET Development Server 10.0.0.0

请帮助我!!!

3 个答案:

答案 0 :(得分:2)

验证以下步骤,

1)在global.axas中验证默认根,如下所示,

routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

2)如果控制器和操作如下,则在URL中提及控制器名称

public class HomeController : Controller
    {
        public ActionResult SetName(int id)
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";

            return View();
        }
    }

然后url将是,

http://localhost:6384/Home/SetName/4

答案 1 :(得分:0)

你应该试试这个:

public ActionResult SetName(int id) {
        return Content("You entered: " id);
    }

抱歉,这比这更容易。您输入的网址不正确。您尚未指定控制器名称。

http://localhost:6384/CONTROLLERNAME/SetName/4

答案 2 :(得分:0)

在此错误消息中。 HTTP状态400错误请求 - 错误语法

可能,因为行动结果无法找到或不存在。

这是错误的操作方法:

// GET: /Name/5
public string SetName(int id)
{
   return "You entered: " + id;
}

我会纠正你的行动方法:

[HttpGet]
public ActionResult Setname(int id)
{
   ViewBag.Result = "You entered: " + id;

    return View();
}