关于Asp.net MVC的一些问题

时间:2021-11-10 15:55:20

I have some questions about some things in Asp.net MVC that still confuses me.

我对Asp.net MVC中的一些事情有些疑问,但仍然让我感到困惑。

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.

湾我怎样才能在VS2008中解决这个问题?当我进行局部视图并且我开始输入时,说<%= intellisense假设我的意思是<%@ Assembly =%>并将其插入。

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?

C。我没有区分ActionResult,ViewResult和PartialViewResult。 ActionResult似乎能够返回所有这些类型的结果。那么为什么要使用其他的呢?

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?).

d。我记得另一个:我知道在做webforms时很多人都希望用IIS连接网站,因为服务器控件和东西可以使用内置的Visual Studio(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?

这样,当您将站点上传到服务器托管站点时,您没有很多问题。这是推荐使用Asp.net MVC吗?

Thanks

2 个解决方案

#1


<% %> 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.

<%%>声明代码块。您在代码块中可以执行的操作类似于函数体。您可以使用多个语句,在C#中,每个语句都应以分号结束。 <%=表达式%>等同于<%Response.Write(expression); %>所以在那里放一个分号是无效的。

I don't think there's an easy workaround for the IntelliSense problem.

我不认为IntelliSense问题有一个简单的解决方法。

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.

是的,实际上,ActionResult是ASP.NET MVC其他类型结果的基类。如果您的操作方法返回类型是ActionResult,则可以从中返回任何类型的结果。 ASP.NET MVC使用返回的对象来查看它应该如何生成响应。

#2


<%= %> is the same as <% Response.Write() %> Just read this

<%=%>与<%Response.Write()%>相同,请阅读此内容

To understand different types of results just read * thread: ASP.NET MVC ViewResult vs PartialViewResult

要了解不同类型的结果,只需读取*线程:ASP.NET MVC ViewResult与PartialViewResult

#1


<% %> 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.

<%%>声明代码块。您在代码块中可以执行的操作类似于函数体。您可以使用多个语句,在C#中,每个语句都应以分号结束。 <%=表达式%>等同于<%Response.Write(expression); %>所以在那里放一个分号是无效的。

I don't think there's an easy workaround for the IntelliSense problem.

我不认为IntelliSense问题有一个简单的解决方法。

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.

是的,实际上,ActionResult是ASP.NET MVC其他类型结果的基类。如果您的操作方法返回类型是ActionResult,则可以从中返回任何类型的结果。 ASP.NET MVC使用返回的对象来查看它应该如何生成响应。

#2


<%= %> is the same as <% Response.Write() %> Just read this

<%=%>与<%Response.Write()%>相同,请阅读此内容

To understand different types of results just read * thread: ASP.NET MVC ViewResult vs PartialViewResult

要了解不同类型的结果,只需读取*线程:ASP.NET MVC ViewResult与PartialViewResult