0

私は自分の製品を注文するために送信するためのそのようなコードを持っています。ブラウザのリンクは次のようになります。http://localhost:22764/Admin/AddToOrder?OrderId=1&WareId=1&WareCount=456しかし、そこに行こうとすると、「/のサーバーエラー」が表示され、404はリソースを見つけることができませんでした。私の見解は次のようになります。

<% foreach (var item in Model) { %>

        <tr>
            <td>
                <%: Html.ActionLink("Edit", "Edit", new { id=item.WareId }) %> |
                <%: Html.ActionLink("Details", "Details", new { id=item.WareId })%> |
                <%: Html.ActionLink("Delete", "Delete", new { id=item.WareId })%> ||||||
                <%: Html.ActionLink("Click Me", "AddToOrder", new { OrderId = 1, WareId = item.WareId, WareCount = item.Quantity })%>

            </td>

            <td>
                <%: item.WareName %>
            </td>
            <td>
                <%: String.Format("{0:F}", item.WareCost) %>
            </td>
            <td>
                <%: item.Quantity %>
            </td>
        </tr>

    <% } %>

そしてコントローラー方式:

 [HttpGet]

        public ActionResult AddToOrder(int OrderId, int WareId, string WareCount)
        {
            OrderRecord or = new OrderRecord();
            or.OrderId = OrderId;
            or.WareId = WareId;
            or.WareCount = WareCount;
            try
            {
                if (ModelState.IsValid)
                {
                    db.AddToOrderRecords(or);
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(String.Empty, ex);
            }
            return View(or);
        }

ルーティングトラブルだと思いますか?お願い助けて。

ルートは:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace Proekt
{
    // 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 = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);
        }
    }
}
4

1 に答える 1

0

ルートデバッガーを使用して、デフォルトルートがURLをキャッチできるかどうかを確認します。ナゲットを介してルートデバッガーをインストールすると、パラメーターを渡すためにViewBagを試すことができます。

于 2012-05-18T21:15:58.793 に答える