我目前有以下链接,可以从一个 View 导航到另一个 View :
"<td class='EmployeeTableTD'><a href='personDetails'>" + item.Name + " " + item.Surname + "</a></td>" +
该表是在 Javascript 中动态创建的,并从 ADO 模型获取数据(项目)。
我想附加参数以将它们传递到 Controller ,然后传递到下一个屏幕的 View 。
我尝试过采用通常的方式
'personDetails?myParameter=' + item.Name
类型的方法,但这导致了 404 错误。我还尝试在代码中插入 @HTML.ActionLink,但这也是有问题的,因为智能感知在尝试设置参数时无法识别“项目”。
有没有办法可以将动态参数从此 View 链接传递到下一个 Controller / View ?
Controller :
using System;
...
namespace techTest4.Controllers
{
public class HomeController : Controller
{
private TechTestEntities techContext = new TechTestEntities();
public ActionResult personDetails()
{
return View();
}
public ActionResult Index()
{
return View();
}
因此,我的导航正确地转到“Home/personDetails”和“personDetails.cshtml” View (其中还没有什么内容,但需要输出传递的参数)。它可以说应该导航到“Home/personDetailsController/{someIndexMethod}”,其中将处理下一页的设置。
配置:
routes.MapRoute(
name: "Details",
url: "PeopleDetails/{action}/{id}",
defaults: new
{
controller = "PeopleDetails",
action = "All",
id = UrlParameter.Optional
}
);
最佳答案
您必须指定您在操作中接收的参数:
public ActionResult personDetails(String myParameter)
{
return View();
}
关于javascript - ASP.Net MVC - 使用 href 从 View 传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43880519/