What is the point of Partial Views in Asp.net MVC

后端 未结 8 1940
北恋
北恋 2020-12-30 00:49

Ive noticed that there seems to be no real difference between a view and a partial view. For instance, one can create a view but can render it as a

8条回答
  •  感情败类
    2020-12-30 01:28

    Two things. First, to an extent you are right. But it's more of a semantic thing to seperate reusable code. It also comes in handy when for e.g. say you need to display a dialog but only when the user has some sort of an interaction with the page, like the click of a button. With partial views you don't have to have the markup for this on the page when it loads thereby reducing the file size. When you write markup/code in the partial view, you don't have to do the whole code block. Instead you just create a

    or whatever you need.

    The bit about creating a view in Visual Studio. No, it's not redundant because when you create a partial view, it does not use your master layout file.

提交回复
热议问题