我试着在asp.net mvc2上使用mvc2模板并使用它。在模板之后,我创建了我自己的模型,控制器和视图,并在其中分别存放了文件夹位置我还为此控制器和视图更改了global.asax中的默认路由。现在我的视图正在被加载,但是当我点击我的视图中的按钮时,我的控制器中写入的方法都没有被击中。可能是什么原因,我错过了什么?我还想在我的视图呈现之前从我的控制器调用预加载方法。请帮助......卡住了。 这里是我的看法ASP.Net MVC 2 - 按钮点击视图不调用控制器中的任何方法?我错过了什么?
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<CreditCashAllocationSystem.Models.ConfigurationModel>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Configuration
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Configuration</h2>
<% using (Html.BeginForm()) {%>
<%= Html.ValidationSummary(true) %>
<fieldset>
<legend>Fields</legend>
<div class="editor-label">
<%= Html.LabelFor(model => model.DropOffDaysForward) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.DropOffDaysForward) %>
<%= Html.ValidationMessageFor(model => model.DropOffDaysForward) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.DropOffDaysBackward) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.DropOffDaysBackward) %>
<%= Html.ValidationMessageFor(model => model.DropOffDaysBackward) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.DealDropOffDateDays) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.DealDropOffDateDays) %>
<%= Html.ValidationMessageFor(model => model.DealDropOffDateDays) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.DealHistoryDays) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.DealHistoryDays) %>
<%= Html.ValidationMessageFor(model => model.DealHistoryDays) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.UnappliedHistoryDays) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.UnappliedHistoryDays) %>
<%= Html.ValidationMessageFor(model => model.UnappliedHistoryDays) %>
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
<% } %>
<div>
<%= Html.ActionLink("Back to List", "Index") %>
</div>
</asp:Content>
,这里是我的控制器:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace CreditCashAllocationSystem.Controllers
{
public class ConfigurationController : Controller
{
//
// GET: /Configuration/Create
//will be called on Form Load
public ActionResult Create()
{
return View("Configuration");
}
//
// POST: /Configuration/Create
//Method will be called once u click on create/save button
[HttpPost]
public ActionResult Create(FormCollection collection)
{
try
{
// TODO: Add insert logic here
return View("Configuration");
}
catch
{
return View("Configuration");
}
}
}
}
这里是我的Global.asax:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace CreditCashAllocationSystem
{
// Note: For instructions on enabling IIS6 or IIS7 classic mode,
// visit http://go.microsoft.com/?LinkId=9394801
public class MvcApplication : System.Web.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 = "Configuration", action = "Create", id = UrlParameter.Optional } // Parameter defaults
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
}
}
}
请帮帮忙,我失去了什么?
做一些断点调试可以帮助证实了这一点。 – xandy 2010-10-30 15:45:06