.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

General Controller to View logic question

Posted By:      Posted Date: September 01, 2010    Points: 0   Category :ASP.Net
Hello, I am currently learning the MVC2 Framework and I have a brief question in terms of my logic and if their are any flaws in it. I created a basic example in a couple of minutes that demonstrates the way I think about it. public ViewResult Index() { return View(); } public ViewResult Cookies() { return View(new Cookie()); } public ViewResult CookiesInput(Cookie cookie) { return View(cookie); }<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <h2>I really like cookies</h2> Would you like a cookie? <% using (Html.BeginForm("Cookies", "Example")) { %> <p><input type="submit" value="Yes" /></p> <% } %> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <h2>Cookies</h2> <% using (Html.BeginForm("CookiesInput", "Example")) { %> <%= Html.EditorForModel() %> <p><input type="submit" value="Gimme" /></p> <% } %> </asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="MainConten

View Complete Post

More Related Resource Links

Model View Controller (MVC) for ASP.NET

Model View Controller (MVC) architectures, immediately wonder how the MVC pattern can be applied in an ASP.NET world. This article will demonstrate how the MVC pattern can be applied to an ASP.NET web application and still maintain the basic Microsoft supplied architecture.

Executing Command Logic in a View Model

Through the use of the Windows Presentation Foundation's (WPF) advanced data-binding capabilities, the logical structure of a user interface can relatively easily be disconnected from its presentation. Bindable components can now contain nearly all of an application's user interface logic and in most circumstances, replace the need for controller objects from the classic Model-View-Controller (MVC) pattern. So it's no wonder that a new pattern for UI design has appeared

Is it bad MVC practice to return a view of a different controller?

I came upon this when had problem trying to return a view of a different controller.  In controller1, I have view view1.In Action1 of controller2, I wanted to do something like:public ViewResult Action1(){     return View("/Controller1/View1");}but, found out, I couldn't do it.  So I searched and found this: http://stackoverflow.com/questions/879852/asp-net-mvc-display-a-view-from-another-controllerOne guy there responded and said that, for my case, it is possible to do things like below:return View("~/Views/Controller1/View1.aspx");But, please let me know if this is considered an acceptable MVC practice.  Is it OK, good, perfect to do so in the asp.net MVC realm?  Thanks, please share your two cents.

General .NET question

Hello, Is there any way to make sure a .NET application does not crash no matter what errors are thrown? TIA.

Noob Question - Using Linq in View

I just inherited an MVC2 application. So far my only experience with MVC is reading the Nerd Dinner sample chapter and downloading the nerd dinner app. I do plan to dive much deeper but i need a quick answer because i have to hit the ground running. So basically in the main Index view the view model is being passed as an IQueryable. Then he is doing some queries on the view model to loop through the data. See example below:<% if (Model.Where(w => w.State == workflowStep.Key).Count() > 0) { %>To me, even though minor, this is business logic and shouldn't be in the view. Shouldn't any type of logic like this be sorted out before you get to the view? Or is this common practice in MVC?Basically i want to know if I should spend time refactoring this thing or just go with the flow.  Thanks.

Passing objects between View and Controller

 I would like to pass List<SelectListItem> (not selected item but the whole "List" object) back to controller.for example in my GET controller i would have thisViewData["list"] = some select list from repository;then on post I would like to get the list back from view..pretty much i'm trying to use ViewData["list"] as storage..this way I would use ajax to remove or add items to/from the list.what's the best approach ?thanks

General question steps to configure mysites in SharePoint 2010

I am trying to configure the mysite web application, so I have created a DNS record "mysite" and created a web application for the mysite and created a mysite host site collection on it. Now I have read somewhere that u have to create managed paths for the profile and the mysite, which actually corresponds with the name of the DNS record/mysite webapp. For some reason when i am opening the mysite, i get a url something like http://my/my. What am i doing wrong? Can somebody just give me a step by step approach on how to configure Mysites in MOSS 2010?I am a SharePoint Infrastructure Engineer, focussed on Administration and Installation of SharePoint Server environments.

General Question for SQL

Hi,  i am working at DB platform since last 2 years ... now i heard about .Net 2010. this platform have lots of new features like (create database, tables and storedprocedure also inbuilded ).. so its affect DBA, DBD prefession for features?..   Thanks in Advance

General Question About Remembering Property Values Between Postbacks

Here are examples of two different ways I've found to story Property values between postbacks:    private bool Initialized    {      get      {        return Convert.ToBoolean(this.Attributes["Initialized"]);      }      set      {        this.Attributes["Initialized"] = value.ToString();      }    }    private int DataTableRowIndex    {      get      {        return (int)ViewState["DataTableRowIndex"];      }      set      {        ViewState["DataTableRowIndex"] = value;      }    }I'd appreciate any comments about differences between these two approaches [Attributes vs. ViewState].  Is one better or worse?Robert

merge repligation general question?

Hello friends Please tell me that what is .sdf file in merge replicaton?

Easy Calendar View Question - I hope

I have a Calendar in Sharepoint Foundation 2010. The only thing I want to do but can't is to have the Event Description text shown along with the Event title. Is it possible? Some event last several hours so there is plenty of space to show the text. TIA

General Setup Question regarding Ssytem.XML assembly

Hello,I have a solution running perfectly well on one machine (or actually quite a few machines).  All the code is in source safe and I am trying to set up a new machine with the solution but keep getting the following build errors:'XName' is ambiguous in the namespace 'System.Xml.Linq'. InternalXmlHelper.vb 'XNamespace' is ambiguous in the namespace 'System.Xml.Linq'. InternalXmlHelper.vb 'XElement'is ambiguous in the namespace 'System.Xml.Linq'. InternalXmlHelper.vb 'XAttribute' is ambiguous in the namespace 'System.Xml.Linq'. InternalXmlHelper.vb and so on...The main difference that I noticed was that on the machines where the application builds, in the property page of the project whgere the build erros are occurring I check the reference list and I see a reference to the System.XML assembly (GAC,  However in the machine with the build errors, even when I try to add a reference to the System.XML assembly I get no error messages, but afterr adding the assembly does NOT appear in the reference list.In addition I have verified that I am able to create a new web application without any build or runtime errors on the machine experiencing these issues.Any feedback would be greatly appreicated.Thanks.

Another 'ViewModel closes the View' question...

Hi all, I'm somewhere in the middle of the learning curve that is the path to MVVM utopia!My question really concerns the ability to close a view from a view model.I don't want to be guilty of trying to force a solution to fit a pattern, but MVVM fits so well in all other areas there's just this one bit left to figure out.The project I'm working on is a system analagous to Microsoft Outlook.You have a main view (window) which has a list of things.These things could be messages or contacts in Outlook.From the main view you have the option to create a new thing or open an existing one.Regardless of which option you choose, a new view (window) opens to present you with a form for editing.From this point on, each new view that opens has the following options (relevant to my question)...1, Save.2, Close.3, Save & Close.Save is pretty straightforward, is just a property on the viewmodel which returns an ICommand (RelayCommand/DelegateCommand).Close is also pretty straightforward, that's just the cross in the top right hand corner of the window.Save & Close, however, is different. With option 2, the close is actually just a part of windows, we're not writing any code to do this.So how would I go about implementing option 3? Where the viewmodel first needs to persist the changes and then needs to close the view?Many thanks,MQCA

Question about adding ASP.NET controls to the page later on via programming logic



I'm pretty new to ASP.NET as you'd expect and I'm coming from a PHP scripting background. I am understanding ASP.NET development so far, however, say you have added many controls onto the web page and later on you want to remove a specific block of controls and add new ones, and this is via programming logic (the backend VB file), how would you go about doing this? Or would you have to go for the approach of adding these controls in a container to the web page first - making them invisible - until you need to use them in your programming logic?



How to retrieve url from another view of controller by code


Dear all

I want to know url of View from another controller.  The following is structure







Now, I want to goto Index view of controller Home from view Login of controller Account

I know  I can use method this.RediectToAction("Index", "Home") to do it but I don't want to method.  It will fail to redirect when view or controller renamed.

Please help



Dear All,

I have

- controller (customer)

public class customer{

public string Name { get; set; }

public string sex {get;set;}


- model (customermodel)

public class customermodel{

public string Name { get; set; }

public string sex {get;set;}


- view (index.aspx)

so i want to transfers presentation model to view (use IList and IEnumberable), how can i do? after i want to display data from database, how can i do ?



tree view OnPrerender Question



Im having the following problem i have a treeview that opens on a pop up window and is being populated from a database table.

What i want is to  add a onClick event to each node as the treeview loads so when i click on a node a javascript function can be called and do something.

How can i take the value of each node that is being populated cause i need to pass it as an argument at the javascript function

public void myTreeView_OnPreRender(object sender, EventArgs e)

        myTreeView.Attributes.Add("onclick", "javascript:doSomething('" + nodeValue + "')");


Thanks in advance


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend