2

Is it safe to say that custom controls with ASP.NET MVC are most times just partial views? And if that's the case, I'm guessing it's always up to the implementing application to dictate the behavior (through controller code) of these controls?

I have done a bit of searching, and there is almost no resources on ASP.NET MVC custom controls (either that, or I'm missing the mark with my Google skills).

4
  • 1
    I think partial views are in place of custom controls for MVC, why you need custome controls for? Commented Nov 3, 2011 at 0:28
  • @EmmanuelN good question. I'm thinking of custom controls for the requirement of something like calendars, menus, etc. I realize these can be created on the fly per application, but code-reusability is best if possible. Commented Nov 3, 2011 at 0:29
  • you are referring to helper methods not custom controls Commented Nov 3, 2011 at 0:39
  • For things like those in mvc, I think is better to rely on client side scripting especially third party scripting libraries like jQuery Commented Nov 3, 2011 at 0:43

2 Answers 2

6

Partial views are more a template for either a control or a set of controls that can be shared between views.

I'm not sure they are "Custom Controls" as such and it sounds like you are coming from an ASP viewpoint.

I think you need to first get in the mindset of MVC and out of ASP.

So for a list of items you may have a partial view that takes the list of items and a partial view that takes an actual item. So "pvCustomerList<List<customer>>" and "pvCustomer<customer>".

The pcCustomerList iterates through the list and creates a pvCustomer for each customer in the list.

Partial Views don't really have code in the controller. Instead they are passed data from the view. If there is a submit action in the partial view, then this is either handled by the controller for the view or a jQuery post back.

I hope this clears things up a little for you.

Have you checked out NerdDinner sample?

Sign up to request clarification or add additional context in comments.

5 Comments

I am a ASP.NET WebForms developer shifting to the wonderful world of MVC (and loving it so far). Say you want to have a calendar, and you want to reuse it with multiple MVC applications. What would be the approach to that? And isn't NerdDinner MVC 1/2? I went right into MVC 3 with the Razor view engine, and I've been a bit hesitant to really analyze non-MVC 3 code and logic as it might throw me off.
@Shark use helper methods for this, write extension method from Html helper class
re-using across applications usually requires you to copy the partial views over. this might also help stackoverflow.com/questions/1532576/…
This isn't in direct relation to the question but also look at jQuery plugins for portability of controls
@MilanJaric you really should make that comment an answer. I think that probably is the best server-side way to have the closest thing to custom controls, as WebForms developers see it.
1

There is nice article on asp.net mvc website regarding form helpers (helper methods for views). there is explained how to create custom helper method

Link is http://www.asp.net/mvc/tutorials/creating-custom-html-helpers-cs

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.