下面是表单代码
@{
ViewData["Title"] = "ModelTrain";
ViewBag.Center = true;
}
<form method="post" class="text-center" asp-controller="Home" asp-action="Index">
<div class="form-group text-center w-50 mx-auto">
<input type="text" name="url" class="form-control my-2" id="url" placeholder="Добавить ссылку профиля " />
</div>
<input type="submit" value="Обучмть модель" class="submit btn btn-secondary" />
</form>
下面是 Controller 代码
public class HomeController : Controller
{
[HttpGet]
public IActionResult Index()
{
return View();
}
[HttpPost]
public async Task<IActionResult> Index(String url)
{
ControlObject control = new ControlObject();
control.body_profile = url;
control.profile = true;
var json = JsonConvert.SerializeObject(control);
var firebaseClient = new FirebaseStorage("hackathontest-e8d57.appspot.com");
var path = @"C:\Users\emiol\source\repos\HackathonFiles\HackathonFiles\TextFile1.txt.txt";
System.IO.File.WriteAllText(path, json);
using (FileStream fs = System.IO.File.Open(path, FileMode.Open))
{
var result = await firebaseClient.Child("TextFileForUrls.txt").PutAsync(fs);
}
return RedirectToAction("Index","Image");
}
}
} ` 当我尝试回发到表单时,它返回 404 错误。在本地测试时不会发生这种情况。有人可以给我指出一个可能的解决方案吗,因为我已经被困在这个问题上很长时间了
最佳答案
尝试删除 div 类并使用如下所示的表单代码:
@{
ViewData["Title"] = "ModelTrain";
ViewBag.Center = true;
}
<form method="post" asp-controller="Home" asp-action="Index">
<input type="text" name="url" class="form-control my-2" id="url" placeholder="Добавить ссылку профиля " />
<input type="submit" value="Обучмть модель" class="submit btn btn-secondary" />
</form>
最有可能的是,您的表单代码编写不正确,并且某些类的解释不正确。首先尝试以下基本方法,然后一一添加您的自定义更改,看看哪里失败(如果上述方法不起作用)。
查看本教程以供引用:https://www.aspsnippets.com/Articles/ASPNet-Core-Form-Submit-Post-Example.aspx
关于c# - 为什么我在 azure 应用程序服务中从表单发布时收到 404 错误,但它在 localhost 中运行良好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65055852/