Is It Necessary - Shared View For Navigation Between Controllers
Mar 16, 2011
I'm very new to ASP.NET MVC and this is probably a really obvious thing...Basically, I can't access the "Forum" view which I had created inside "Home" folder (because I need a link to Forum on my main homepage.). I was wondering if it's okay to just move the Forum view into the Shared folder?
Is this somehow very bad practice? It seems like I have strong coupling now, because on the one hand the forum view gets called inside HomeController, and on the other hand it will pretty much always be used with ForumController from now on. So that might be unnecessary/wrong somehow?
edit: If I do this, the URLs change in a weird way, there must be a better solution right?
First when I click on forum link on main page, I'm at: /Home/Forum. I look at the forum, everything is fine.
Now I click on "Post a topic", and after the roundtrip I'm at /Forum/PostTopic.
I have ContentView which has 'Table of Contents' and another view (DescriptionView) which has the total description of these contents. Each content description in DescriptionView is in different sections and I have implemented accordion to manage this.
[Code]....
When I click on each content in ContentView I navigate to that particular section in the DescriptionView by the of the anchor tag which i specify in the url. My issue is I am not able to open that section which will be hided using accordion. Hope am successful in explaining my query.
I have ContentView which has 'Table of Contents' and another view (DescriptionView) which has the total description of these contents. Each content description in DescriptionView is in different sections and I have implemented accordion to manage this.
[Code]....
When I click on each content in ContentView I navigate to that particular section in the DescriptionView by the of the anchor tag which i specify in the url. My issue is I am not able to open that section which will be hided using accordion. Hope am successful in explaining my query.
I have a partial view (user control) that is shared by my Create and Edit views. When I use it in the Edit view, I have to to include an hidden field (Html.HiddenFor) to prevent a 'Row changed or not found' error in my data service, but when I use it in the Create view, I have to remove the PK hidden field, to prevent an error over trying to insert into an identity column. It is not feasible to not use identity columns in this application, so how can I 'switch' that PK hidden field on or off depending on which action has been invoked?
Post Action Code:
[HttpPost] public ActionResult Edit(JobCardViewData viewData) { try { jobCardService.Update(viewData.JobCard); Edit View Excerpt: <% Html.RenderPartial("JobCardInput", Model); %> Partial Excerpt: <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Poynting.Installation.Web.ViewData.JobCardViewData>" %> <% using (Html.BeginForm())
I want to call a non shared function in a shared function in which i am having a textbox control instance. Its giving no error but when i call this shared function from client callback it gives me no response
Any Idea except removing shared from the function.
Here is my code :
<WebMethod()> _ Public Shared Function myF() As String Dim pg As New _Default Return "{'Hello':'" & pg.setText & "'}" End Function Public Function setText() As String Dim pg As New _Default pg.TextBox1.Text = "This is a test" Return pg.TextBox1.Text End Function
i'm in a project with a service layer (WCF), a proxy layer that are between this service layer and the "controllers". Every controller should call this proxy layer to get data, and instead return a model to be rendered, returns a bigger entity that i've to convert using Linq to a more little model. Then pass it to the view.
Do you think is a good idea that this conversion be done by the controller? In my opinion the controller is not the responsable to shape the incoming object from the proxy layer. This object should be returned by the proxy layer and the controller should pass it to the view directly.
I want to test that when my form data is posted back to my controllers that the data annotations and the model binding is going to do its job and give the correct model state. After googling for a while I can't find a really good tutorial or article that shows how to do this.
Can anyone point me in the right direction? What is the best practice in this area? I have read that I may need to use moq and MVCContrib but I have not read a tutorial that makes me shout, "Yes, this is the right way to do it!"
I'm starting a new ASP.NET MVC project, and I decided to put my controllers in a different assembly. Evertyhing works fine, but I have hit a problem: I created a new area in my MVC Project, called Administration. I have an AdminController Class in my seperate assembly which is supposed to return views from my Admin area, but everytime it tries to return a view, it looks for it in the wrong place (~/Admin/SomeView.cshtml Instead of ~/Administration/Admin/SomeView.cshtml) How can I tell the controller to look for views in the wanted area?
I am wanting to create a path somewhat like this: /Administration/News and have it forward to a News controller instead of it being the action.How would I go about this?
I was wondering what the major differences are between controllers and webservices. I understand webservices can receive postbacks via ajax while controllers cannot. Also, when you put a webservice in a MVC site, what file structure do you use to store it? Just create a single services folder?
Basically what the title says. I created a new MVC application. I'm trying to add new pages to the site, but anytime I do I get the following error:Server Error in '/' Application.The resource cannot be found.Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
namespace MyAppMVC.Controllers { public class ProductsController : Controlle{ public ActionResult Index() [code]...
I'm currently migrating a WebForms app over to MVC. One problem I have is that some users will probably have a page like www.mysite.com/login.aspx bookmarked (or maybe some other .aspx page). Currently this will throw an InvalidOperationException stating that the controller 'login.aspx' could not be found. Is there any way I can handle this so that it redirects the user to another page?
I know I can implement Application_Error in the Global.asax file, but I'd rather not redirect on any InvalidOperationException, just when it's an invalid controller.
I would like to have a project that contains all of my Controller logic. I'm not concerned with using Areas, as these are still maintained within the same project. Consider this scenario: I have multiple sites/apps that require the exact same interaction in regards to a particular area, say CRUD ops on a user account. I do not want to create all of the controller logic for one site/app, recreate it again for the next, and make sure that I keep all maintenance to each in sync. I would prefer to keep the controllers in a separate project and reference them from the appropriate site.
I know someone will say that the controller logic is a lot of times specific to the application (as I've read elsewhere), but let's just say that it is guaranteed to be the same. I want to focus on the "how" and not the "why". So far, I've created a class library project with the appropriate references for accessing System.Web.Mvc. How do I proceed with the routing configuration for this? Is this idea even possible? I read a few older articles that were written when Areas were first being introduced that said to create separate projects for them. Is this idea similar to that?
I am developing a restful web api using asp.net mvc and trying to extend the MVCWEBAPI project on codeplex that i took from here - http://code.msdn.microsoft.com/MvcWebAPII have added a folder nested within API folder inside the Controllers folder.This path does not work - (nested folder Security)http://localhost/API/Security/Authentication/LoginAlthoug, this path works - (not nested)http://localhost/API/Media/GetMediaThe folder structure is Controllers ->APIWithin API folder I added a Security folder and then added AuthenticationController under it.To make the routing work, I updated global.asax.csBelow is the required code.
public static void RegisterRoutes(RouteCollection routes) { var map = new NameValueCollection();
I mean parameters of methods of controllers. For example, I have a View, which has :1. One radiobutton Yes / No (table inside DB has bit field)2. dropdownlist with int values (table has int too)3. Textbox (Firstname for example)I can create a method:
Does it make sense to do error handling and logging inside actions methods or handle the OnException method inside the controllers. One way means writing try/catches in all the action methods even when there is nothing to be done to recover from the error. Handling this at the controller level would allow logging and redirection to an error handler page without writing try/catches inside all the action methods.
Which method makes the most sense? Here is example code of try/catches in an action method.
[HttpPost] public ActionResult Delete(int id) {[code]...
For applications that need to have fastly different view layers, and I would like to still use the idea of the controller. I would ideally like to but the controllers in a Class Lib. and then have only the Views in a MVC Web Application. Taking the model out in this way works well, but I can't find a nice way to split the views and controllers.