html - When to use Partial view in ASP MVC? -


i have page has 4 hidden divs, there 4 buttons bring corresponding divs. instead of writing code on 1 page, have split partial views (so divs in partial views) e.g.

<div class="hide" id="doctor">     @html.partial("~/views/medical/_doctor.cshtml") </div> 

it feels wrong reason this, doesn't it?

i don't see reason why "wrong". if helps reduce complexity of code, helps.

partials typically used following reasons (but not strictly):

  1. for child actions , ajax requests
  2. for reuse of common code
  3. to simplify complex pages

the thing watch out if pass object partial it's model, may not render form fields in correct manner bound on postback. editortemplates for, although if know you're doing can make partials work well.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -