表单操作现在指向';r.ashx';使用MVC 3

本文关键字:ashx 使用 MVC 操作 表单 | 更新日期: 2023-09-27 18:19:32

突然间,我的表单链接看起来像这样:

<form action="/r.ashx/Models.Module_ContactUs?action=Submit&amp;controller=Contact" id="contactUsForm" method="post">

这以前是有效的,但IIS似乎发生了一些变化。

代码:

@using (Html.BeginForm("Submit", "Contact", FormMethod.Post, new { id = "contactUsForm" }))
{
    <div class="contact-form">
        <h4><strong>Send Us a Message</strong></h4>
            <div class="form-row">
                @Html.LabelFor(model => model.Form.Name, "Your Name *")
                @Html.TextBoxFor(model => model.Form.Name, new { tabindex = 1, @class = "field blink" })
                @Html.ValidationMessageFor(model => model.Form.Name, "First name required.")
            </div>
            <div class="form-row">
                @Html.LabelFor(model => model.Form.Name, "Your Email *")
                @Html.TextBoxFor(model => model.Form.Email, new { tabindex = 2, @class = "field blink" })
                @Html.ValidationMessageFor(model => model.Form.Email, "")
            </div>
            <div class="form-row">
                @Html.LabelFor(model => model.Form.Name, "Subject *")
                @Html.TextBoxFor(model => model.Form.Subject, new { tabindex = 3, @class = "field blink" })
                @Html.ValidationMessageFor(model => model.Form.Subject, "Subject required.")
            </div>
            <div class="form-row">
                @Html.LabelFor(model => model.Form.Message, "Your Message *")
                @Html.TextAreaFor(model => model.Form.Message, new { tabindex = 4, @class = "field blink" })
                @Html.ValidationMessageFor(model => model.Form.Message, "Message required.")
            </div>
            <div class="form-buttons">
                <input type="submit" value="Send Message" class="submit-button" id="SubmtButton" tabindex="5" />
            </div>
    </div>
}

Global.asax

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapRoute("BlogArchive", "Blog/{year}/{month}", new { controller = "Blog", action = "FilterByMonth" }, new { year = @"'d+", month = @"'d+" });
            routes.MapRoute("BlogRedirect", "Blog/Redirect", new { controller = "Blog", action = "Redirect" });
            routes.MapRoute("BlogListingFiltered", "Blog/{filterBy}/{filter}", new { controller = "Blog", action = "Filter" });
            routes.MapRoute("BlogCategories", "Blog/Category/{categoryFriendlyName}", new { controller = "Blog", action = "FilterByCategory" });
            // 404 page...
            routes.MapRoute("Errors", "Errors/{action}", new { controller = "Error", action = "Error" });
            // Error Pages
            routes.MapRoute("Error", "Errors/{errorCode}", new { controller = "Error", action = "Error", errorCode = UrlParameter.Optional });
            // Agility Builtin Route
            routes.MapRoute("Agility", "{*sitemapPath}", new { controller = "Agility", action = "RenderPage" });
            // needs to be here, after agility routing for url generation to happen
            routes.MapRoute("Contact", "Contact/{action}", new { controller = "Contact", action = "Submit" });
            //default method for action/controller
            routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Error", action = "Error", id = "" });
        }

Web.config

<httpHandlers>
      <add path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler, dotless.Core" />
      <add path="glimpse.axd" verb="GET,POST" type="Glimpse.Core.Handler" />
    </httpHandlers>
    <trace writeToDiagnosticsTrace="true" enabled="true" pageOutput="false" />
    <httpModules>
      <add name="Glimpse" type="Glimpse.Core.Module" />
    </httpModules>

表单操作现在指向';r.ashx';使用MVC 3

将这行代码添加到global.asax中的RegisterRoutes解决了问题:

routes.Clear();