开发者

Asp.NET MVC strong typed controllers

开发者 https://www.devze.com 2022-12-21 18:23 出处:网络
I saw somewhere code like this: return View(x=>x.List()); Instead of return View(\"List\"); What do I need to achieve this ?开发者_开发知识库

I saw somewhere code like this:

return View(x=>x.List());

Instead of

return View("List");

What do I need to achieve this ?开发者_开发知识库

I'm using Asp.net MVC 2 RC 2

EDIT I do not mean strong typed views

Next example

return this.RedirectToAction(c => c.Speaker());


Strongly Typed RedirectToAction is provided by the MvcContrib project.

return RedirectToAction(c => c.Speaker());

return RedirectToAction<OtherController>(c => c.Speaker());


It's not the controller that's strong typed... it's the view.

To get a strongly typed view, you can either use the prompts from the VS MVC tools, and right click on an action and choose "Create a strongly-typed view", then select the proper business object to act as your model, or you can directly alter a page by changing it's Page directive's Inherits attribute to System.Web.Mvc.ViewPage, where SomeModel is the model that implements the "List" property and is the model that will be bound to the page.

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<SomeModel>" %>

Also, I believe what you're thinking about is the usage on the View:

<%= Html.LabelFor(m -> m.SomeValue) %>

Again, I don't believe you're thinking about a strongly typed controller, I'm pretty sure what you saw was a strongly typed view.

If you go through the NerdDinner tutorial, you'll see this kind of thing time and time again.


I am not sure what you would expect as a return from a call to a View method taking a different controller action as a parameter. As you have pointed out RedirectToAction has this behaviour as well as some Html helper methods such as:

<%= Html.ActionLink<myController>(x => x.Index(), "My Action") %>
0

精彩评论

暂无评论...
验证码 换一张
取 消