ASP.NET MVC 并将 ID 传递给强类型 BeginForm
我在将 id 从 URL 传递到控制器操作时遇到一些问题
假设我有这个 Url:Bing/Index/4
在我的母版页中,我想生成一个提交到 BingController SearchAction 的表单。我做了这样的事情
using(Html.BeginForm
如何从 url 获取 id(本例中为 4)并将其传递给搜索行动?
感谢您的帮助
I have some problems on passing an id from URL into my controller action
Lets say I have this Url : Bing/Index/4
In my master page I would like to generate a form that submits to BingController SearchAction. I did something like this
using(Html.BeginForm<BingController>(action => action.Search(id)))
How to get id (4 in this example) from url to pass it to the Search action ?
Thanks for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要访问母版页中的数据,您的控制器需要将其添加到 ViewData 中,以便母版页可以访问它。
然后在母版页中,您可以在 ViewData 中访问它。
对于强类型视图,我有一个 BaseModel 类,它具有母版页所需的属性,并且我的所有其他模型都继承基类。像这样的东西......
你的母版页看起来像这样:
To access that data in a master page, your controllers would need to add it to the ViewData so the master page has access to it.
Then in your master page, you can access it in the ViewData
For a strongly-typed View, I have a BaseModel class that has properties that the master page needs and all my other models inherit the base class. Something like this...
Your master page would look like this: