【发布时间】:2022-08-03 01:00:00
【问题描述】:
非常新的 MVC 并通过了一些教程。做过以下事情:
添加一个名为 CustomerController 的控制器。 添加2个方法
public ActionResult Render()
{
// Go to a third party WebAPI and get the results in a List
return PartialView(\"CustomerList\", custList);
}
public ActionResult SomeTest()
{
Response.Redirect(\"Somepage\");
}
然后我添加一个页面 (LandingView.cshtml) 并创建一个名为 CustomerList 的 PartialView 并将以下代码添加到 LandingView 页面
@Html.Action(\"Render\", \"Customer\")
当我查看此页面时,它会呈现带有客户列表的页面。 PartialView 的 HTML 是
@using (Html.BeginForm(\"SomeTest\", \"Customer\"))
{
<div class=\"container\">
@foreach (var i in Model)
{
<a href=\"@i.Url\">
<div class=\"product-grid__item__name\">@i.Title</div><br />
<div class=\"product-grid__item__price\">@i.Price.ToString(\"C\")</div>
</a>
<input type=\"button\" id=\"btnGo\" value=\"Go\" />
}
</div>
}
当我单击按钮时,它永远不会点击 SomeTest 方法?在调试模式下,我在Render 和SomeTest 上设置了一个断点,在页面加载时渲染命中,但是当单击Go 时它从未命中SomeTest 方法?
我在这里想念什么?
标签: c# asp.net-mvc razor razor-pages