我有一个从ActionLink调用被调用两次的控制器。
我的主页有一个链接,当单击时调用播放控制器上的索引方法。将100的id传递给该方法。我认为这是导致这个问题的原因。以下更多内容
以下是一些代码段:
主页:
<%= Html.ActionLink(“Click Me”,"Index","Play",new { id = 100 },null) %>
播放控制器:
public ActionResult Index(int? id) { var settings = new Dictionary<string,string>(); settings.Add("Id",id.ToString()); ViewData["InitParams"] = settings.ToInitParams(); return View(); }
播放视图:
<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage" %> (html <head> omitted for brevity) <body> <form id="form1" runat="server" style="height:100%"> Hello </form> </body>
如果我摆脱了Index方法的参数,一切都很好。如果我把参数保留在原来的位置,那么Index方法被调用为100作为id。返回View后,方法再次被调用,参数为null。
我似乎无法弄清楚什么是触发第二个呼叫。
routes.MapRoute( "Play",// Route name "Play/{id}",// URL with parameters new {controller = "Play",action = "Index"} // Parameter defaults );
我不知道从这里去哪里。
先谢谢你。
Rick
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。