Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

Pass data to User Control ASP.NET MVC -


i have user control shows list of latest announcements. user control used in 90% of pages. concern how pass data user control latest announcements.

my first approach make base controller , in initialise method pass data user control via viewbag/viewdata. other controllers derive base controller. looks nice concern may become overkill simple solution existing out there. need make sure no controller ever fiddles viewdata/viewbag data meant usercontrol.

please let me know if correct way of proceeding ahead or there exists better solution.

thanks

assuming have "user control" (you should try refer them partial view's in mvc) looks this:

<%@ control language="c#" inherits="system.web.mvc.viewusercontrol<ienumerable<announcement>>" %> 

this means partial view expects list of announcement objects.

now, question - where rendering partial view?

you doing master page, doing view, or doing partial view.

either way, code render partial needs this:

<% html.renderpartial("latestannouncements", announcements) %> 

but - announcements from.

assuming have repository/dal/helper method latest announcements - think should have viewmodel's require inheriting base viewmodel:

public class announcementviewmodelbase {    protected ienumerable<announcement> getannouncements()    {        // call dal    } }  

then master/view/partial needs render latest announcements partial should bound viewmodel inherits base view model.

in cases master/view/partial not strongly-typed (e.g dynamic view), can stick in viewdata. if have organized view's correctly shouldn't required.


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -