来自URL(GET)的调用方法 [英] Call method from URL (GET)
本文介绍了来自URL(GET)的调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好!
在视图中我有链接:http:// localhost:54149 / Users / Delete / 13
和控制器:
Hello!
At view i have link: http://localhost:54149/Users/Delete/13
And controller:
public ActionResult Delete(int Idaccesso)
{
if (Idaccesso != null && Idaccesso != 0)
{
}
}
This controller returns error:
The parameters dictionary contains a null entry for parameter 'Idaccesso' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Delete(Int32)' in 'CMSPI.Controllers.UsersController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
If it replace on:
<pre lang="sql">public ActionResult Delete(int Idaccesso = 0)
{
if (Idaccesso != null && Idaccesso != 0)
{
}
}
Than only keep Idaccesso = 0, because Idaccesso set by default.
How will be?
推荐答案
什么是
MapRoute $您的
MvcApplication
的c $ c>?它是这样定义的吗?
What''s the
MapRoute
of yourMvcApplication
? Does it defined like this?
public class MvcApplication : HttpApplication
{
// ...
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
//...
}
尝试从 Idaccesso
到 id
。
这篇关于来自URL(GET)的调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文