Mvc - Can Set A Custom Class As The Default Base Class For Controllers In MVC3

Feb 15, 2011

I'd like to inherit all my controllers from a custom base class that I write myself. I can change the line every time I add a new controller, but it would be nicer if I could somewhere specify the default value that gets set there. That way I wouldn't need to worry about forgetting this, and other people who get added to the project later on would have an easier time.

View 3 Replies


Similar Messages:

Base Class Of Razor View In ASP MVC3

Oct 18, 2010

I'm trying to have all my views inherit from a custom class so that I can add certain behaviour and values to all pages, but I'm having some issues. I tried subclassing System.Web.Mvc.WebViewPage but I'm forced to implement an Execute procedure that I don't know what it should do. Also, if I try to access the Context variable, I get a null reference (really weird). This leads me to think that I may have the wrong base class.

View 1 Replies

WebMatrix :: How To Change The Default Page Base Class

Aug 16, 2010

I've tried setting the <pages pageBaseType="DynamicWebPage" /> value in web.config, but when I response.write out the page type, I'm still getting Microsoft.WebPages.WebPage.

I'm simply trying to sub-class WebPage and add some additional functionality such as a dynamic PageData dictionary similar to Phil Haack's dynamic ViewData dictionary.

View 3 Replies

Add A Custom Base Class For Web Forms?

Jan 12, 2010

I want to add a custom base class for all of my web forms. I created a "App_code" folder in my asp.net web project and add a simple base page class like this:

namespace MySite.Web
{
// base page for all the pages that need localization
public class LocalizationPage : System.Web.UI.Page
{
protected override void InitializeCulture()
{
base.InitializeCulture();
}
}
}

And then I try to let asp.net web form to inherit from this base page. I have something like this:

using MySite.Web;

namespace MySite.Public
{
public partial class RegisterPage : LocalizationPage
{
}
}

Now I run into problem where Visual Studio doesn't recognize the LocalizationPage class I created. On the above code snippet, LocalizationPage is not highlighted as a class. And when I try to compile, I got the following error message:

Error 1 The type or namespace name 'LocalizationPage' could not be found (are you missing a using directive or an assembly reference?)

View 1 Replies

C# - How To Access A Private Data Members Of Base Class In The Derived Class

Aug 20, 2010

Since we can access the private data member of base class in the derived class with the help of friend function. How can we do the same in C# asp.net? I mean whats the alternative of friend function in C# asp.net

View 2 Replies

C# - Webservice Complex Types And Class Inheritance - Use The Properties Of The Base Class?

Mar 13, 2010

Using the following Webservice definition using aClientArgs as a complex type:

[System.Web.Script.Services.ScriptService]
public class Controller : System.Web.Services.WebService {
[WebMethod]
public void save_client(aClientArgs client)
{
// Save client data
}
}
Then defining aClientArgs as a sub-class:
public class aArgs
{
public string id = null;
public string name = null;
}
public class aClientArgs : aArgs
{
public string address = null;
public string website = null;
}
Returns the following WSDL fragment for the save_client args:
<save_client xmlns="http://tempuri.org/">
<client>
<address>string</address>
<website>string</website>
</client>
</save_client>
When I'm expecting the following:
<save_client xmlns="http://tempuri.org/">
<client>
<id>string</id>
<name>string</name>
<address>string</address>
<website>string</website>
</client>
</save_client>

So it appears that the .NET WebService is not treating inherited properties as arguments/variables for purposes of a web service. How do I get .NET to also use the properties of the base class?

View 1 Replies

MVC :: Trying To Setup A Base Product Class That Will Be Inherited By A More Specific Class Later?

Dec 16, 2010

In my MVC project, I am trying to setup a base product class that will be inherited by a more specific class later. Here is my scenario. I have a table called ProductBase, it contains three fields, BaseProductId(PK), CatalogNum, and ListPrice. Every product in the system will share these attributes. Next, I have a table called Shirt, with three fields BaseProductId(PK, FK), Color, and Size.

I then setup an Entity Data Model that pulled in both of these tables and created classes BaseProduct and Shirt. So, in my model, I want to do something like this:

[Code]....

The main problem I have with this, is that if I do any kind of condition on CatalogNum or ListPrice, then my performance goes to crap. One of the main things we will want to do is something like this:

[Code]....

This takes an enormous performance hit, and I suspect it is because the partial class above returns to the database for each shirt.

The other problem I have with this approach, is that I cannot force the properties for the Shirt. What if I make a change to the BaseProduct? What happens when I have multiple product types, will I have to repeat this code? I assume I will need to make a change with the entity data model, but I am unsure where to begin.

View 5 Replies

MVC :: Access HTTPContext And Session From Custom Base Controller Class?

Jan 13, 2010

I built a base controller class inherits from Controller class to add some custom behavior to all controllers which will inherit from this base class.

My issue is when I try to access HTTPContext and Session objects in my custom base class, they are always null.

Am I doing something wrong or need missing something?

My custom base class definition:

public class ApplicationControllerBase : Controller

controllers classes definition:

public class HomeController : ApplicationControllerBase

using ASP.NET MVC 1, .NET 3.5.

UPDATE:

It seems the issue is I try to access HTTPContext in the constructor while HTTPContext is not ready yet, I tried it in the OnActionExecuted event handler and it works fine.

My question is what is the best place to access Session object in my custom controller class, that will guarantee executing my code with all controllers.

View 3 Replies

WCF / ASMX :: Web Service To Inherit From A Custom Base Class That Inherits System.Web.Services.WebMethod Inste...

Oct 18, 2010

Recently, I tried to get my Web Service class to inherit from a custom base class that inherits from System.Web.Services.WebMethod instead of the System.Web.Services.WebMethod directly.

However, I've been getting Error 500.

Public Class Service1
Inherits BaseClass
<System.Web.Services.WebMethod()> _
Public Function GetSessionID() As String
GetSessionID = Me.Session.SessionID
End Function
End Class

public class BaseClass
Inherits System.Web.Services.WebService
public property Property1 as string
public property Property2 as string

End Class

View 6 Replies

Call Always Base Class Method Like Base.OnInit()?

Jun 29, 2010

I am new in asp .net.I am not able to undestand why we call base class method when we
override methods/events.Like automatically visual studio will put base.OnInit() if you are overriding OnInit.

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
}

same is the case of Finalize. In derived we call base.Finalize() Is there any need of calling these base class methods ?

View 2 Replies

MVC :: Embed Mvc Controllers And And Models Into Class Library?

Aug 10, 2010

We have a solution that contains 2 web applications and a class library called core.dll that has our shared code for use on both sites. What I was wondering is: is there a way when integrating MVC into our current application to put things that may be common across both sites like controller classes into the shared class library?

View 2 Replies

MVC :: UML Class Diagram For Application Include All The Controllers And Views And Their Relationships?

Mar 16, 2011

I would like to ask a plain and simple question about the Model-View-Controller architecture - should the UML Class diagram for my application include all the controllers and views and their relationships, or should it just include my model classes, i.e. the entities that are the heart of the application, you know - like in an ordinary application - i.e. User, Administrator, Student, Teacher, Course, Grade etc...?

View 1 Replies

C# - Extending The Base Class?

Mar 5, 2010

When you create a webpage in ASP.net, the codebase inherits System.Web.UI.Page

Now when I extend the page object to check for SessionExpired for example, I create a new class and inherit from system.web.ui.page, and overwrite some functions.

The problem then is that on each page, I have to replace system.web.ui.page with my custompage class.

Is there a way to extend a class by adding methods or modifying its methods directly (e.g. add the sessionExpired check to System.Web.UI.Page) ?

I'm using .NET 2.0

View 2 Replies

Base Class Access A Parameter?

Feb 15, 2010

Is it possible for a Controller Base class to access a parameter from an action link and if so how do I access that parameter within my Base Controller?

Action Link:

<%=Url.Action("Area_1419", "Home", new { SectionId = 1})%>

Base Controller Class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Website.Models;
namespace Website.Controllers
{
public abstract class CategoriesController : Controller
{
public CategoriesDataContext _dataContext = new CategoriesDataContext();
public CategoriesDataContext DataContext
{
get { return _dataContext; }
}
public void SectionID()
{
int SectionID = Convert.ToInt32(Request.QueryString["SectionID"]);
ViewData["SectionID"] = SectionID;
}
public CategoriesController2()
{
//ViewData["Categories"] = from m in _dataContext.Categories where m.Area_ID == SectionID select m;
//ViewData["Categories"] = from c in DataContext.Categories select c;
}
}
}

HomeContoller

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Website.Models;
using Website.ActionFilters;
namespace Website.Controllers
{
[HandleError]
public class HomeController : CategoriesController
{
public ActionResult Index()
{
return View();
}
public ActionResult About(int? SectionID)
{
//ViewData["Message"] = SectionID;
return View();
}
public ActionResult Area_1419(int SectionID)
{
return View();
}
public ActionResult Admin()
{
return View();
}
}
}

View 2 Replies

C# - What Layer Does A UserControl's Base Class Belong

Aug 28, 2010

I have an asp.net usercontrol (ascx) that inherits from an abstract class (that inherits from a UserControl). My Project is in a 3-tier architecture (DAL -> Bll -> UI/Views). Currently there are no class files in the UI layer (other than the code-behinds). Which layer should I add this abstract class to?

View 2 Replies

C# - Inheriting From A System.Web.UI.UserControl Base Class?

Feb 28, 2011

First off, I am wondering if this is possible. I read slight grumblings around the internet about this, but I was not entirely sure.

My scenario: I have a base chart class which has some methods which all charts should have.

public partial class BaseChart : System.Web.UI.UserControl
{
public BaseChart()
{
}
public void ToggleLegend()
{
Chart1.Legends[0].Enabled = !Chart1.Legends[0].Enabled;
}
}

There is also some mark-up for this BaseChart -- setting background colors, etc. All charts which inherit BaseChart should use this starting mark-up and be able to build upon it.

I would then like to do this:

public partial class HistoricalLineChart : BaseChart
{
public HistoricalLineChart()
: base()
{

public HistoricalLineChart(int reportID)
: base()
{
Chart1.Titles[0].Text = "Hello World";
}
}

where HistoricalLineChart is a web user control with no mark-up e.g. "HistoricalLineChart.ascx"

The problem is that Chart1 is undefined when in HistoricalLineChart's scope. Is there something that I am missing here?

View 3 Replies

Chained Base Class Properties Not Injecting

Apr 2, 2010

I am successfully injecting base class properties with spring.net with just a class that inherits from a base abstract class. Lets say Class MyClass : MyBase, and I am successfully setting a property like this:

<object id="myInstantiableClass" type="myAssembly.MyClass myAssenbly" abstract="true">
<property name="MyBaseClassProperty" ref="anotherObjRef"></property> </object>

Where MyBaseClassProperty is a property on the base class. Now I have another abstract class between the old base class and the instantiable class and I am trying to set properties on both the abstract classes. So MyClass : MyNewBaseClass and MyNewBaseClass : MyBaseClass. I have an additional property on the new base class (MyNewBaseClassProperty) and I am trying to inject it like this:

<object id="myInstantiableClass" type="myAssembly.MyClass myAssenbly" abstract="true">
<property name="MyBaseClassProperty" ref="anotherObjRef"></property>
<property name="MyNewBaseClassProperty" ref="someOtherObjRef"></property>
</object>

The property on the old base class is being injected but the one on the new one is not - and I am not getting an error or anything (so I am pretty sure my config is good), that property is just null! I am on asp.net (not MVC) and the class MyClass is a user control (ascx).

View 1 Replies

C# - How To Execute Page_Load() In Page's Base Class

Apr 29, 2010

I have the following PerformanceFactsheet.aspx.cs page class

public partial class PerformanceFactsheet : FactsheetBase
protected void Page_Load(object sender, EventArgs e)
// do stuff with the data extracted in FactsheetBase
divPerformance.Controls.Add(this.Data);
where FactsheetBase is defined as
public class FactsheetBase : System.Web.UI.Page
[code]...

View 3 Replies

MVC :: Assign Values To Base Class Properties?

Sep 29, 2010

In my controller have a FormViewModel which inherits from a domain class declared in dbml. In the constructor of the FormViewModel I want to do a shorthand assignment to the inherited class properties with the passed in object (ie thisPerson) without iterating through each property of the inherited class and assigning its value with corresponding property in the passing in object. Should I use super, base, this, or something else?

[code]....

View 1 Replies

Web Forms :: Invoking Methods In The Base Class?

Mar 8, 2011

We have a base class that all our webpages in our application inherit from. I have a static method in the base class which when called will clear values from the application cache. Now the issue is this method needs to be triggered from a source outside the current application. I there any way this can be accomplished without creating an aspx page that will call this base method on page load.

View 1 Replies

C# - Databind A Gridview To A Field In A Base Class?

Nov 16, 2010

I have the following classes (pseudocode):

Item ( int Field1 )
ItemDetail : Item (int Field2, string field3)

If I set ItemDetail as the datasource for an asp.net gridview:

grid.DataSource = new List<ItemDetail>();
grid.DataBind();

Can I use Field1 in the GridView? If so, what is the correct DataBinder syntax? The following code blows up trying to cast to an Item:

<%# DataBinder.Eval(Container.DataItem, "Field1") %>

EDIT: And I'm a moron. I had copied the gridview and was calling a RowDataBound event handler for a different grid... Sorry to have wasted everyones time, but there is some good info here regardless if anyone has the same question. In the end, the public properties of the base class are binding correctly.

View 2 Replies

Put The Database Connection Settings Into A Base Page Class?

Mar 16, 2010

it's possible to put the database connection settings into a base page class so that I can auto-init them on a page. like this document: [URL] but with instructions in VB.net

View 1 Replies

Web Forms :: Access Maser Page In Base Class?

Mar 9, 2010

I have a class BasePage this class inhereted from System.Web.UI.Page, all my other pages inhereted from BasePage.

How i can access Master page in BasePage ? To access master page at any page i use :

Template masterPage = Master as Template; where Template class of my Master page.

View 1 Replies

Web Forms :: Base Class Page Load Not Called?

Jun 24, 2010

I have the below structure. Admin_note --> AdminBasePage --> System.Web.UI.Page.But Page_Load does not call in AdminBasePage when calling page_load in Admin_note class.Do you know how to solve??

//// One file///
namespace UI.Admin
{

[code]...

View 6 Replies

MVC :: Downcasting To Base Class Strongly Typed View?

Oct 29, 2010

I have the following entity object:

[Code]....

Then I have page that would has a list of ForumPost(s) and and edit option, all on one page. To achieve this I've created a CommentsViewModel that extends "ForumPost" class like so:

[Code]....

This way on my view I can have a list of ForumPost(s) and a form that would edit the post.This is what i see in the debug mode right before the save call:The problem is that when I try to Save/Update I get the following error:I already tried doing this:

[Code]....

with no luck. for some reason downcasting doesn't work and the model or row are still of type CommentsViewModel instead of ForumPost

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved