Я пытаюсь преобразовать свой код из Get to Post, и по какой-то причине он дает мне:
Ошибка сервера в приложении '/'.
Ресурс не найден,Описание: HTTP 404. Ресурс, который вы ищете (или одна из его зависимостей), возможно, был удален, изменилось его имя или временно недоступен.Пожалуйста, просмотрите следующий URL и убедитесь, что он написан правильно.
Запрашиваемый URL: / Home / ColorMixer
Для получения рабочего кода у меня есть В HomeController.cs:
[HttpGet]
public ActionResult ColorMixer()
{
double Retval = 0;
string MetricUnitsString = Request.QueryString["Metric"];
double Miles = Convert.ToDouble(Request.QueryString["Miles"]);
Retval = Miles * 1.60934;
if (MetricUnitsString == "millimeters")
Retval *= 1000000;
else if (MetricUnitsString == "centimeters")
Retval *= 100000;
else if (MetricUnitsString == "meters")
Retval *= 1000;
else if (MetricUnitsString == "kilometers")
{ }
else
{
ViewBag.Message = "";
return View();
}
ViewBag.Message = Miles + " miles is " + Retval + " " + MetricUnitsString;
return View();
}
В ColorMixer.cshtml:
@{
ViewBag.Title = "Mile Converter";
}
<h2>@ViewBag.Title</h2>
<div class="row">
@using (Html.BeginForm("ColorMixer", "Home", FormMethod.Post))
{
<div class="col-md-6">
<p><label for="Miles">Miles</label></p>
@Html.TextBox("miles")
</div>
<div class="col-md-6">
@Html.Label("Color2Label", "Second Color")
<div class="w3-container">
@Html.TextBox("Metric")
</div>
<input type="submit" />
</div>
}
</div>
<p>@ViewBag.Message</p>
Единственное, что отличается между этим кодом и неработающим почтовым индексом -
В HomeController.cs:
[HttpGet]
становится
[HttpPost]
И в ColorMixer.cshtml
@using (Html.BeginForm("ColorMixer", "Home", FormMethod.Get))
становится
@using (Html.BeginForm("ColorMixer", "Home", FormMethod.Post))
Я установил контрольные точки и не могу понять, почему это вызывает истерику.