ASP.NET MVC:什么是操作方法?行动结果?它们有何关系?
我很抱歉问这样一个基本的问题,但这对我来说是基本的。为了更好地理解过滤器,我需要理解这个概念。虽然我已经使用 ASP.NET MVC 几个月了,并且正在做一些不错的演示,但我对 Action 方法概念比 Action 结果更熟悉。
什么是:
- 行动方法?
- 行动结果?
- 它们有何关系?
假设我有
public ViewResult ShowPerson(int id)
{
var friend = db.Persons.Where(p => P.PersonID == id).First();
return View(friend);
}
这些概念如何应用于上面的代码?
谢谢你的帮助。
I'm sorry to ask such a basic question, but it's kind of fundamental for me. To better understand filters, I need to understand this notions. Although I'm on ASP.NET MVC for few months now and now are doing nice demos, I'm more familiar with Action method concept than action result.
What are:
- Action Method?
- Action Result?
- How are they related?
Let's say I've this
public ViewResult ShowPerson(int id)
{
var friend = db.Persons.Where(p => P.PersonID == id).First();
return View(friend);
}
How those concepts apply to the above code?
Thanks for helping.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的示例中,
ShowPerson
是操作。每个操作都需要返回一个操作结果(在您的情况下它返回一个视图)。因此,当调用控制器操作方法时,它会进行一些处理并决定哪个视图最适合表示模型。您可能会使用许多不同的操作结果。它们都源自 ActionResult:
In your example
ShowPerson
is the action. Each action needs to return an action result (In your case it returns a view). So when a controller action method is invoked it does some processing and decides what view would be best adapted to represent the model.There are many different action results that you might use. They all derive from ActionResult:
@Darin-dimitrov 的回答非常切题。但我也看到 MSDN 上给出的解释非常有帮助。
Answer by @Darin-dimitrov is very much upto the point. But I see explanation given on MSDN also very much helpful.