Web Forms :: How To Change Normal Class To Controller
Jan 24, 2016Is there any way to convert our class to controller in asp.net MVC ....
View 1 RepliesIs there any way to convert our class to controller in asp.net MVC ....
View 1 RepliesI've created a nice menu class and used it in my MasterPage like "using My.GeneralRoutines".This class is working well and everything is fine UNTIL I want to access this same instance of that class that was created at MasterPage level on "a_page.aspx.cs" (this page is using the MasterPage like :)
[Code]...
my MVC2 delete and only my delete controller is refusing to return any class information. Its really similar to my edit function and the views are all auto-generated so I don't see the problem.
Function Delete(ByVal id As Integer) As ActionResult
How do you get the current action / controller name in a controller or class?
i can't show it in my view but that's not what i want.
I am using vs 2010, mvc, linq to sqlMy Model is .dbmliletbl_teacher,tbl_class,tbl_subject etc are involvedI write code in my controller for table join.
[Code]....
I've been working on a rather large web application that requires a specific id param in the url for every page visited (for example, /controller/action/id?AccountId=23235325). This id has to be verified every time someone visits a page. want to reduce code replication as much as possible, and was wondering if there is a way to use an init method or constructor in a controller that inherits the MVC controller, and then have that controller extended by the others.
View 1 RepliesI have a facade class that my controller class calls out to and in that facade class, for whatever reason, I'm building a string a href element. And it resolves fine in casini but when it gets out in the real world like localhost it doesn't work. Is there a way to do this?
string goBackLinkForErrorMessage = "<br /><a href='/MyController/Action?id=" + blah + "'>Go Back</a>";
Hi I have created the following controller i want to add view that should have the data access class UserMagnament.Controller.menuitems but when i add view by right clicking on view folder,it is not showing "UserMagnament.Controller.menuitems" in add data class
No controller is shown such as homecontoller, accounts controller, UMController(My Controller) etc i have converted my solution from mvc 1 to mvc2. i checked the web.config. it seems ok for MVC2
[Code]....
How to pass the textbox value to my controller there is no form and post method in the viewpage.I have taken one input type textbox which is not bind with my model.I need to access that value to controller
View 13 RepliesIn My Project I want to Create a Class Library Contains a Controller based on its module, Example : Class.Controllers.Album,Class.Controller.Artist
in this Class Library I wrote two Controllers AlbumController.cs, ArtistController.cs.When I add this to Main Project Contains Views,
I am creating an ASP.NET application that allows users to edit and insert data that is persisted in a SQL Server database.I would like to implement a controller class that handles queries for certain entities, caches results and triggers events when data is inserted or updated.I need one of these controller classes for each entity in my data model.What I'm unsure of is how to create a singleton class of this sort that different user sessions can access.
For example,I have a Employee entity in my data model.I would like to have an EmployeeController class that handles retrieving the employees from the database, sends inserts and updates to the database,keeps a cache of all employees and triggers events when an employee is inserted or updated.Objects in other user sessions could then listen and respond to these events.
Am I on the right track?Should I be using the ASP.NET MVC framework to accomplish this?How do I instantiate these controller classes when the first user needs them and have subsequent concurrent users access the same class?
EDIT:I've been researching the idea of a controller class as an anti-pattern since @TomTom's answer.I'm not convinced one way or the other.I still need an answer to question #3 above.Let's just drop the specific idea of a controller class for now. How do I create any class that is:accessible by multiple user sessions,allows only one instance,is deleted if there are no user sessions,and triggers events that other classes can listen to.
I am having problems adding a reference to a custom assembly in my Bin folder within a controller class I am writing. I can see the dlls in the Bin folder of my Solution file and when adding a new 'using' block to the top of code page, its not picking up any of my assemblies as I try to spell them out.I tried just typing them in and building the solution, but I get errors, it just wont pick these up!
View 3 RepliesI 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.
I'm using a simple base class for my controller that sets a piece of ViewData and makes use of the HttpContext. My understanding is that I need to put this code in Initialize() or OnActionExecuting(). I tried both, but believe Initialize() is what I want.
This works when running the app in VS just fine.
I wrote a unit test that calls the action and checks the ViewData for the expected value. When unit testing, neither method is called.
Assume the current executing action method is Index() in Home controller. From within Index(), how to obtain the physical file path of the Home controller? Assume we don't know the file structure until runtime.
View 2 RepliesBy default ASP.NET MVC uses ContentResult for controller method that return result not inherited from actionresult type. That is why if we will return some poco entity it will be only its type name.Could I overload something in controller to make it return jsonresult by default.Example:// return json product representation instead of product typename
public MyController: Controller
{
public Product MyAction()
{
return new Product { Name = "Foo", ID = 1 };
[code]...
Is it possible to change Properties of ViewData.ModelMetadata in Controller?. For example, can I do the following to change the display information of the LogOnModel:
[Code]....
When I do that there is no errors but DisplayName is not change. I'm trying to localize strings to different languages and also to make some attributes of the model different depending on users roles.
I have a questions..
when initially page load I have two radio button in the page..
Add
Edit
when I select Add radio button I need to go the controller Action Add
$("#Add").change(function () {
// what should I write here to hit the controller?
});
Ho to change Wizard1.ActiveStepIndex from the WZ.vb class
View 2 RepliesI want to change the class of an object dynamically in C#
Main Class : handleOperator objOpr = new handleOperator();
Then for object objOpr I need to access the methods for another class Class2 :
Means, I want objOpr = new Class2();
UML and Patterns: An Introduction to Object-Oriented Analysis and Design and Iterative Development, that follows the UP(Unified Process). It uses a Grasp Controller pattern to interact with domain classes by some methods like NewSale(), AddNewItemToSale() and CloseSale. In windows form, I can instantiate a object of this class in the UI and then use its methods to perform the actions. This works well in Client apps, but when I use asp.net mvc, I cannot find a way to instantiate an object (one for each user) that was always visible for a Controller (MVC). I cannot insert as an attribute inside Controller because it always create a new one.
View 1 RepliesI have a requirement whereby I need to be able to change the controller being used based upon a parameter. I am creating an application that needs to be dynamic enough to be able to change controllers on the fly. Let me explain further;
When the application starts a dictionary of custom controller names is loaded with a controller name as the key and a custom controller name as the value. This will be help in the application scope.
When a request is made I need to access the requested controller name, use that name and check to see if it matches a key in my controller dictionary and if so, replace the requested controller name with the custom controller name from the dictionary.
example;
My dictionary will contain data as follows
Key: 'Home', Value: 'Home_IN'
Key: 'Customer', Value: 'Customer_BE'
Now, the following request is made 'User/Edit/1'. Does the controller name exist in the dictionary? No, continue with original request.
Now, the following request is made 'Home/Details/2'. Does the controller name exist in the dictionary? Yes, replace the original controller name 'Home' withe custom controller name 'Home_IN' so changing the requested URL to be 'Home_IN/Details/2'.
Does this make sense?
My problem here is knowing exactly where in the request cycle I need to do this?
I am assuming I need to create my own custom controller factory?
I have just upgraded a large project to MVC 2 (50+ controllers) and whilst the project builds fine I am having issues in several places because it looks like the way the Controller.UpdateModel method handles emtpy strings has changed.
In MVC 1 it set the associated property to an empty string but in MVC2 it's setting it to null.
I have just upgraded a project from MVC 1 to 2 and I have come across an issue with fields updated via UpdateModel which contain an emtpy string.
In MVC 1 the associated property would be set to String.Emtpy or "", but in MVC 2 it's set to null. This is causing me all kinds of problems
to change ItemStyle-CssClass of TemplateField in the code behind?The intellisense for itemstyle in C# is read-only..
View 1 Replies