Note that there are some explanatory texts on larger screens.

plurals
  1. POOverriding MVC Controller When Controller In a Separate Class Library
    primarykey
    data
    text
    <p>This is my VS solution:</p> <pre><code>Core Library - contains Controllers Project A - references Core Project B - references Core </code></pre> <p>Both projects have routing based on the referenced Core Library. However, I want to override certain Controller functions based on which project (a.k.a. "site") is calling the function. I've tried creating Project B Controller that inherits from Core Library Controller, making the Core function virtual and setting the Project B Controller function to "overrides". However, the Project B Controller was never even called.</p> <p>Is this possible? How can I have the Core Controller functions be overridden by the Projects?</p> <p>UPDATE: Post is updated based on comments below, but still not sure why this won't work in MVC.</p> <p>Here is the code for the controller in Project B:</p> <pre><code>public class BaseController : Controller { public StateLevelViewModel GetStateLevelLandingResults(string State, int level) { var data = GetStateCityBreakdown(stateAbbrev, level); } public virtual List&lt;StateCityBreakdownModel&gt; GetStateCityBreakdown(string stateAbbrev, int level) { return db.Database.SqlQuery&lt;StateCityBreakdownModel&gt;("GetCountsByStateAndCity @state, @level", new SqlParameter("state", stateAbbrev), new SqlParameter("level", level)).ToList(); } } public class BaseController : XYZ.Controllers.BaseController { public override List&lt;StateCityBreakdownModel&gt; GetStateCityBreakdown(string stateAbbrev, int level) { return db.Database.SqlQuery&lt;StateCityBreakdownModel&gt;("GetCountsByStateAndCityForPartnership @state, @level, @partner", new SqlParameter("state", stateAbbrev), new SqlParameter("level", level), new SqlParameter("partner", 2)).ToList(); } } </code></pre> <p>UPDATE 2 : inheriting controller is just plain ignored. Issue is that project won't recognize the controller at all.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload