属性的参数路由号码404未找​​到 [英] Attribute routing number of parameters with 404 not found

查看:103
本文介绍了属性的参数路由号码404未找​​到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用AttributeRouting设置特定航线为我的ActionResult。我没有找到一个404页时,我有这个配置:

I use AttributeRouting to set specific route for my ActionResult. I got an 404 page not found when I have this configuration:

[GET("Tender/SubmitBid/{id}/{bidId}")]
public ActionResult SubmitBid(string id, string bidId)
{ 
 ...
 return View(model);
}

@using ("SubmitBid", "Tender", new { id = Model.TenderId, bidId = Model.BidId }, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
 ...    
 <button type="submit">Save</button>
}

// 404 not found
[HttpPost]
public ActionResult SubmitBid(BidViewModel model)
{
 ...
}

我安装了一个网址嗅探器来查看该URL触发没有找到404页,我得到这样的:HTTP ... /招标/ SubmitBid / 1/0

I installed a url sniffer to see the url trigger the 404 page not found and I got this: http.../Tender/SubmitBid/1/0

这应该是工作...但我要删除最新的参数来达到的ActionResult,我不知道为什么。

It supposed to be working... but I have to remove the latest parameters to reach the ActionResult and I don't know why.

感谢你的帮助,

卡琳

修改
如果我删除属性[GET(招标/ SubmitBid / {ID} / {} bidId)的页面是POST请求进行访问。但是URL是类似于http ... //招标/ SubmitBid / 1?bidId = 0

Edit If I remove the attribute [GET("Tender/SubmitBid/{id}/{bidId}")] the page is accessible for the POST request. But the url is like http...//Tender/SubmitBid/1?bidId=0

推荐答案

,因为它们在 BidViewModel 您发布存在您应该不需要查询字符串参数。 POST请求的一点是,你没有查询字符串参数。

You should not need the query string parameters since they exist in the BidViewModel you post. The point of a POST request is that you don't have query string parameters.

我认为你必须使用此重载的 <一个href=\"http://msdn.microsoft.com/en-us/library/system.web.mvc.html.formextensions.beginform%28v=vs.108%29.aspx\"相对=nofollow> Html.BeginForm 方式:

I think you have to use this overload of the Html.BeginForm method:

@using (Html.BeginForm("SubmitBid", "Tender", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.HiddenFor(model => model.Id)
    @Html.HiddenFor(model => model.BidId)

    // Other properties..

    <button type="submit">Save</button>
}

现在将张贴到 HTTP:本地主机/招标/ SubmitBid BidViewModel 的属性后的值,包含编号 BidId 。在POST操作的签名可以保持相同的:

Now it will post to http:localhost/Tender/SubmitBid with the properties of BidViewModel as post values, which contain Id and BidId. The signature of the POST action can stay the same:

[HttpPost]
public ActionResult SubmitBid(BidViewModel model)
{
    string id = model.Id;
    string bidId =  model.bidId;

    // ...
}

这也有可能是AttributeRouting导致此问题。你可以用本地ASP.NET MVC路由试试这个?您可以使用此特定路由提交投标:

It's also possible that AttributeRouting causes this issue. Can you try this with native ASP.NET MVC routing? You could use this specific route for submitting bids:

routes.MapRoute(
    name: "SubmitBid",
    url: "Tender/SubmitBid/{id}/{bidId}/",
    defaults: new 
                { 
                    controller = "Tender", 
                    action = "SubmitBid", 
                    id = UrlParameter.Optional, 
                    bidId = UrlParameter.Optional 
                });

这篇关于属性的参数路由号码404未找​​到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆