Reputation: 85855
I have some questions about some things in Asp.net MVC that still confuses me.
a. I am still confused when I should be using <%= %>
and when I should use this <% %>(this one seems to need a semi colon at the end).
b. How can I fix this in VS2008? When I make a partial view and I start typing say <%=
intellisense assumes I meant this <%@ Assembly= %>
and inserts that in.
It really gets annoying to type in a partial view file.
c. I don't get the difference between ActionResult, ViewResult
and PartialViewResult
. ActionResult
seems to be able to return all of these types of results. So why use the other ones?
d. I remembered another one: I know when doing webforms many ppl like to to hook up the site with IIS since the server controls and stuff can be rendered different using the built in Visual Studio thing(Cassi?).
That way when you upload your site to a server hosting site you don't have has many issues. Is this recommend with Asp.net MVC too?
Thanks
Upvotes: 1
Views: 225
Reputation: 5935
<%= %> is the same as <% Response.Write() %> Just read this
To understand different types of results just read stackoverflow thread: ASP.NET MVC ViewResult vs PartialViewResult
Upvotes: 1
Reputation: 422182
<% %>
declares a code block. What you can do in a code block is similar to a body of a function. You can have several statements and in C#, every one of them should be terminated by a semicolon. <%= expression %>
is equivalent to <% Response.Write(expression); %>
so it's invalid to put a semicolon there.
I don't think there's an easy workaround for the IntelliSense problem.
Yes, in fact, ActionResult
is the base class for other type of results ASP.NET MVC. If your action method return type is ActionResult
, you can return any type of result from it. ASP.NET MVC uses the returned object to see how it should generate the response.
Upvotes: 1