保存MVC 5时出现点尾故障

时间:2018-11-19 16:42:01

标签: entity-framework asp.net-mvc-5

我有这个模型项可以修改并保存在MVC 5中。 (.NET Framework 4.6.1)

@using (Ajax.BeginForm("Edit", new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "wrapperViews" }))
    {
        @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>EQUIPMENT - @ViewBag.EQP_ID</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        @Html.HiddenFor(model => model.ID)
        @Html.HiddenFor(model => model.OPERATIONID)

        <div class="form-group">
            @Html.LabelFor(model => model.DESCRIPTION, htmlAttributes: new { @class = "control-label col-md-4" })
            <div class="col-md-8">
                @Html.EditorFor(model => model.DESCRIPTION, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.DESCRIPTION, "", new { @class = "text-danger" })
            </div>
        </div>



        <div class="form-group">
            @Html.LabelFor(model => model.TYPE, htmlAttributes: new { @class = "control-label col-md-4" })
            <div class="col-md-8">
                @Html.DropDownListFor(model => model.TYPE,
                       new SelectList(Model.EquipmentTypes, "CodeType", "DescriptionType"),"", new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.TYPE, "", new { @class = "text-danger" })
            </div>
        </div>
        <div class="form-group">
            <div style="width:500px;margin-top:15px">
                <div style="width:120px; float:left;margin-left:30px">
                    <input type="submit" value="Save" class="btn btn" />
                </div>
                <div style="width:120px; float:left;">

                    @Ajax.ActionLink("Back to the list", "Index", "Equipment", new { id = Model.OPERATIONID }, new AjaxOptions()
                    {
                        OnSuccess = "OpenEquipment"
                    })

                </div>
            </div>
        </div>
    </div>

问题在于要修改的实体字段名称中包含点,如下所示:

  http://localhost:62396/controllername/Edit/SUPREP.ABL

提交表单时出现错误

HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

Detailed Error Information:
Module     IIS Web Core
Notification       MapRequestHandler
Handler    StaticFile
Error Code     0x80070002
Requested URL      http://localhost:62396/controller/Edit/SUPREP.ABL
Physical Path      C:\projectname\controller\Edit\SUPREP.ABL

我尽了一切努力,但没有解决麻烦。 任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:2)

刚刚解决。需要将以下行添加到RouteConfig.cs:

routes.AppendTrailingSlash = true;

一切正常。谢谢。

答案 1 :(得分:0)

问题出在您的URL上。 IIS认为您正在请求扩展名为“ .ABL”的文件。您只需添加尾随/即可使其像路线一样。

例如:http://localhost:62396/controllername/Edit/SUPREP.ABL/

还要通过将其添加到web.config来确保启用了双重转义:

import colorama
colorama.init()

print_in_green = "\x1b[32m"
print_in_red = "\x1b[31m"
print_in_blue = "\x1b[36m"
print_in_pink = "\x1b[35m"
print_default = "\x1b[0m"

import random
min = 1
max = 6
game_response = input("Would you like to roll your dice (y/n)? ")

# Create variable to store the accumulated score
total_score = 0

if game_response == "y":
    roll_again = "yes"

    while roll_again == "yes" or roll_again == "y":
        print("Rolling the dices...")
        print("The values are:")
        dice1 = random.randint(min, max)
        dice2 = random.randint(min, max)
        print(print_in_pink)
        print(int(dice1))
        print(int(dice2))
        print(print_default)
        score = (int(dice1) + int(dice2))
        roll_again = input("Your score for this round is " + str(score) + ". Roll the dices again (y/n)? ")
        total_score = total_score + score
    print("Here is your score:",total_score)
else:
    print("Ok!")