ViewModels Versus Presentations, Or Both?

Apr 28, 2010

Previously to learning about ViewModels and AutoMapper, my infrastructure project had the following classes defined:

Csharp Code:

[code]....

View 2 Replies


Similar Messages:

Configuration :: Deploying Versus Releasing Versus Implementing

Sep 16, 2010

What is the difference between; Deploying an application Releasing an application Implementing an application

View 1 Replies

Application_Start Versus OnInit Versus Constructor?

Jul 23, 2010

I've gone rounds with this ever since I started programming classic ASP 12 (or so) years ago and I've never found a great solution because the architecture of ASP and ASP.NET has always been a swamp of bad practices, magic shared singletons, etc. My biggest issue is with the HttpApplication object with its non-event events (Application_Start, Application_End, etc.).

If you want to do stuff once for the entire lifespan of an HTTP application, Application_Start is the obvious place to do it. Right? Not exactly. Firstly, this is not an event per se, it's a magic naming convention that, when followed, causes the method to be called once per AppDomain created by IIS.

Besides magic naming conventions being a horrible practice, I've started to think it might be a reason there exist no such thing as a Start event on the HttpApplication object. So I've experimented with events that do exist, such as Init. Well, this isn't really an event either, it's an overridable method, which is the next best thing.

It seems that the Init() method is called for every instantiation of an HttpApplication object, which happens a lot more than once per AppDomain. This means that I might as just put my startup logic inside the HttpApplication object's constructor.

Now my question is, why shouldn't I put my startup logic in the constructor? Why does even Init() exist and do I need to care about Application_Start? If I do, can anyone explain why there is no proper event or overridable method for this pseudo-event in the HttpApplication object?

And can anyone explain to me why in a typical ASP.NET application, 8 instances of my HttpApplication are created (which causes the constructor and Init to run just as many times, of course; this can be mitigated with locking and a shared static boolean called initialized) when my application only has a single AppDomain?

View 2 Replies

How To Get ID Of EditorFor With Nested Viewmodels In Mvc 2

Mar 30, 2010

So I have two nested view models, CreditCard -> BillAddress. I have a view, "EditBilling", that has EditorFor(CreditCard). The CreditCard EditorTemplate has EditorFor(BillAddress), and the BillAddress EditorTemplate has EditorFor(BillState).

The end result is a select list with id "CreditCard_BillAddress_BillState".

I need to reference this in javascript, thus need to know the ID. In other situations, with non-nested ViewModels, I have used the following code:

$('#<%= ViewData.ModelMetadata.PropertyName %>_BillState')

The problem here is that the ModelMetadata.PropertyName property is only aware of the current property, not the parent(s). So I end up with the following:

$('#BillAddress_BillState')

How does one go about getting the client ID of nested strongly typed helpers?

View 1 Replies

Duplicating Properties In ViewModels

Nov 25, 2010

I have a question regarding the duplication of properties within view models. For my Search View i have a viewmodel that looks like this

public class SearchModel
{
public IEnumerable<SelectListItem> Genders {get;set;}
... other select lists
// Worker Details
public string FirstName {get;set;}
public string LastName {get;set;}
public DateTime Birthdate {get;set;}
public int Phone {get;set;}et
public string Gender {get; set;}
//Address Details
public string Street {get;set;}
public string City {get;set;}
public string Zip {get; set;}
}
For my Input View i have the following View Model
public IEnumerable<SelectListItem> Genders {get;set;}
public IEnumerable<SelectListItem> Directions {get;set;}
... other select lists
// Worker Details
public string FirstName {get;set;}
public string LastName {get;set;}
public DateTime Birthdate {get;set;}
public int Phone {get;set;}et
public string Gender {get; set;}
public string SSN {get; set;}
public string DL {get;set;}
//Address Details
public int Number {get;set;}
public string Direction {get;set;}
public string Suffix {get;set;}
.....
public string Street {get;set;}
public string City {get;set;}
public string Zip {get; set;}
}
List Display Model
public class ListDisplayModel
{
public IEnumerable<Worker> Workers {get;set;}
internal class Worker
{
public string FirstName {get;set;}
public string LastName {get;set;}
public DateTime Birthdate {get;set;}
public int Phone {get;set;}et
public string Gender {get; set;}
public string SSN {get; set;}
public string DL {get;set;}
//Address Details
public int Number {get;set;}
public string Direction {get;set;}
public string Suffix {get;set;}
public string Street {get;set;}
public string City {get;set;}
public string Zip {get; set;}
}
}

I feel like i'm duplicating a lot of properties. I was wondering if it would be ideal for me to go ahead and create like a DTO class called worker and just place it in each of these view model classes or is there a better way to do something like this?

View 2 Replies

MVC :: ModelBinder For Dependency Injection On ViewModels?

Jan 25, 2011

This project is pretty far away and I'm not in the position to go make changes all over the place (If I could, deleting the lot would be what I'd do!)

I want to create a modelbinder that would resolve any dependencies my View Models might have (using StructureMap).

It should not require me to implement a specific interface (so many developers, so many interfaces..I rather keep things clean) and hopefully not require one to go register each model binder individually (Now I'm asking too much,taking the first requirment
in consideration).

Probably will get it right tonight, but figured I'd ask.

View 3 Replies

All Viewmodels Inherit From 'BaseViewModel', Can Set This Up In OnActionExecuting

Jan 22, 2011

If all my actions have a model that inherits from BaseViewModel, is it possible to initialize this model from the OnActionExecuting method?

Currently in all my actions I do this:

var model = new SomeModel();
model.User = Users.Get(...);

Now I am loading the user object in OnActionExecuting, so I was hoping I could setup my model from there somehow.

View 1 Replies

MVC :: ViewModels And Updates And Where To Create Gui Elements?

Mar 21, 2011

I have relates to how we update using a view model. I am trying to pin down whether a viewmodel is disposed once a View is rendered to the browser or whether the viewmodel continues to exist even after the View has been rendered.

Essentially I have in my viewmodel the following code:

[Code]....

This is used to bind html elements in my view so if I need to make a modification to a Item contained in the list can I simply access this and post the VM back to the controller or do I need to post a Item object back to the controller in the singular. Secondly where is the best place to build a gui control such as a table. If in the view I have a foreach loop and write out table fields is this the most appropriate way of achieving this or should I deal with this in the Controller or Model and pass it to the gui in the View Model?

View 1 Replies

C# - Pass Nested Lists From View To Controller Using Viewmodels?

Mar 24, 2011

I am Francesco and I am newbie. I have a problem with ASP.NET MVC3 regarding the data posted between View and Controller. My goal is to use a form to edit a specific record from my database and then post it back to the controller, which is in charge of checking the record's fields and submit them into the database.
The data are passed from the Controller to the View by using a ViewModel and therefore the DefaultDataBinding does not apply in this case. I tried many approaches, I monitored the communication with Fiddler but I couldn't solve my problem. The method described by Phil Haack does not work and neither does the FormCollection.

Here you have the code:

ViewModels: I pass it to the View to create a table. Name and the list of Item names (table columns headers) are just to be displayed. I want to have back the Id, the Month (they are passed correctly as parameters and represents table row headers) and most important the ActualValue of the Items and their Id (I have an association table in my database with Id, Itemid and Month as keys)

[Code]....

View: The View is strongly typed as ViewModels.EditViewModel and sends the fields through a submit button. I have to generate a table by using foreach loops, because I do not know how many items there are in advance

Controller: The controller has to update each kpi passed from the view related to a specific Id and Month.

[HttpPost]
public ActionResult EditMonth(int Id, int Month, //FormCollection kpiValues)

View 1 Replies

VB.Net Versus C Sharp

Aug 18, 2010

which is the better language in terms of coding, proficieny if we compare between VB.Net and C Sharp.

View 7 Replies

Winform Versus MVC

Jun 1, 2010

I want to know when to use winform and MVC asp.net

View 11 Replies

SQLDataSource Versus ADO.NET

Mar 8, 2011

If I want to connect to a database in ASP.Net, is it better to use ADO.NET rather than SQLDataSource? They serve a similar purpose, correct?

View 7 Replies

Website Versus Web Application

Mar 29, 2010

I am using VS 2008/VB.Net and am trying to figure out if I should use a "Website" or a "ASP.Net Application" project type.

I have to create an online tool to allow users to manage data, there should be no more than 5-10 users at a time on the system. I need to use Profile/Membership with the tool.

I plan to use the <correction> N-layer </correction> (not "n-tier") architecture with a Business layer and DB layer.

I am wondering about the advantages/disadvantages of each.

Is the "website" model really outdated? I notice that the Website model has in built support for many more namespaces but with asp.net application does not, you have to add a lot of references.

View 5 Replies

CSS Versus Master Page

Jul 31, 2010

my application uses a master page from which every other page inherits and also an external style sheet.

the problem i have is that once a messagebox pops up while running the application(maybe due to an error that was caught) the "content" part of the page loses the styles that were applied to them from the external style sheet. Only the Master page part of the page still retains the external styles.

assistance, will be very welcome.

Incase this might be useful too: i use the Response.Write method to call the javascript "alert" function to display pop ups.

View 2 Replies

MVC Versus Ruby On Rails

Nov 30, 2010

If you were starting a new web development project would you use ASP.Net MVC 2 or Ruby on Rails?

I have recently invested some time in to learning Ruby on Rails because I wanted to learn a solid web development framework. Then I took a new job where I will be using ASP.Net MVC 2.

I know this question is very subjective, but I am planning to write some websites on my own, outside of work, and I would like to get some opinions from others.

View 4 Replies

SqlDataSource Versus ADO.NET Coding With C#

Feb 25, 2011

I really do not have time to learn new language, in my case asp.net, but would like to start developing website in asp.net. I do not want to use asp:SqlDataSource control. is it ok if i write in codebehind aspx: all database connections and other CRUD operations in ado.net and c#. I already know xhtml, javascript - jquery, css, xml, json, some knowledge in sever-side coding (before php). want to start coding, instead of learning messy asp.net controls.I have to sit and learn all bloody ways of using those asp.net controls?

View 2 Replies

C# - Umbraco Versus Sitefinity

Oct 19, 2010

I am getting a large website developed. The develop has asked me which do I prefer either sitefinity or umbraco. The site will be similar to wikipedia where users can come and edit pages without having to login. I would like to ask your opionions on these two csm systems and which one would you recommend for content website with a community feel and wiki features.

View 5 Replies

Python Django Versus MVC

May 21, 2010

break up the pros and cons of using python django vs asp.net mvc besides the maturity level of its framework. I have intermediate experience with JAVA. As of right now, i'm leaning towards python but i just wanted to make sure i am making the right choice.

I find myself limited with books available on asp.net web developments. I am aware that there is the storefront example on the official asp.net site. However, that tutorial was a little hard for me to follow. I've done a research around and was python could be my next available choice. There are more tutorials available online for python anyways.

View 1 Replies

Properties Versus Parameters

May 21, 2010

you have a class and the class has a function that returns a dataset. If the function requires a few values to return data how do you determine whether you create parameters for the function or create private fields and get and set properties and just call the properties get functions?

Properties option
private x as integer = 0
function getX()
return x
end function
function setX(xValue as integer)
x = xValue
end function.......

View 3 Replies

Using LINQ Contains Versus SqlMethods.Like?

Jan 29, 2010

How do I replicate the following result in my LINQ query without calling in the helper library System.data.Linq.SqlClient?

Where SqlMethods.Like(e.POSITION, "%A[FGL]7%") _

I would like this query to be more purely LINQ if possible.

View 3 Replies

Advantage Of Themes Versus CSS?

Jan 24, 2010

Since Themes in ASP.NET are used to style elements of your site, I was just wondering why would you use Themes rather than CSS, or is it common practice to use both? If so, when would you opt for one versus the other and why?

Just seems to me like Themes are kind of unnecessary, so I am just looking on clarification if there really is a good reason to use them, or it's just a part of the framework as an alternative(unnecessary) step to styling your site.

View 2 Replies

Running The Project Versus Viewing In IIS

Nov 19, 2010

This could be a simple one but it has got me baffled. I have a ASP.NET solution that I have stored in C/inetpub/www/root/website. The solution and project files are all stored in there and I have set it up as a virtual directory in IIS.so I can view the web page in 2 ways.

1. - By running the solution [URL]

2. - By viewing the url in IE: [URL]

I changed the project to use windows authentication and I added alabel in the top right of the page which displays the user logged in i.e. DOMAINusername.

When I run the solution from VS2008 it displays the username on the page no problem (that is my logon id since I am running it). But when I view the page by typing the URL into IE - it doesnt seem to recognise the authentication and it doesnt display my DOMAINusername in the label.

Any ideas why this is? I thought maybe it was something to do with the .dlls but I did a simple test. In the project I created a new a label on the page and in the page_load I wrote "label.text = "Test Text". In both cases the label showed "Test Text" as expected so it is nothing to do with building the solution. Is there something about windows authentication - why would it work in one case and not in the other? So as a third test I actually opened IIS and right-clicked on the my website in the console and choose "browse".

I then got the following error:

Sequence contains no elements

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Sequence contains no elements

Source Error:

[Code]....

Now I set a break point at this point in my project in VS2008 - but when I run it there it doesnt even go to this code!

View 3 Replies

String Builder Versus Repeater (which Is Best)

Jun 29, 2010

I have written such a code to loop through the records and build a string.

Is this s good idea or should I use repeater or something?

[code]....

View 5 Replies

Biggest Advantage To Using MVC Versus Web Forms

Sep 22, 2010

Possible Duplicate:

MVC versus WebForms

What are some of the advantages of using one over the other?

View 2 Replies

C# - Strings Versus Controls In WebForms

Mar 24, 2011

why can images not be appended to a div in asp?

divHtml.append(img);

why do I have to use div.controls.add(img);?

and why cant I add a string to controls.add say like this

div.controls.add(img + String.Format("{0}", reader.GetString(0));

?

Orginally "In the beginning"

I had this code:

[code]....

View 5 Replies







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