MVC :: Managing Add Vs Edit Models?
Apr 22, 2010
I've half written an app which has just one model for adding and editing a particular entity.I am trying to embrace modelmetadata and where possible reduce my form code to just calls for EditorForModel. One of the key issues I am having it managing the
differences between a add and update scenario.
Take "User" editing for example, in an Add scenario I want "Password" to be a required field, in an update scenario I dont' want it to be a required field. The model-centric approach would have me create two models, one for adding and one for editing. My
edit model wouldn't have the Required attribute on the Password field. My feeling is this is going to create a bit too much plumbing.
Besides having a rather massive amount of automapping going on there is another more irrititating issue. Strongly typed views. I could... maybe see my way to having a different model for create and edit, using inheritance i could.. maybe mitigate the amount of code required. What I can't abide is having to have two seperate views, as I have already coding myself into a wall with strongly typed views I couldn't share add and edit (based on my understanding) scenarios with one view.
So anyway I was wondering what other peoplle are doing to manage this? Working with an outsourced (Indian) developers it would be great to make use of EditorForModel as I want them writing as little code as possible.
View 14 Replies
Similar Messages:
Mar 15, 2011
I have a MVC3 solution named "SampleProject". I have 4 projects in the solution.
The project names of the solution are
SampleProject.Data (holds entity classes, DAL classes, and filter classes)
SampleProject.Service (something like BLL in standard ERP)
SampleProject.Tests (test project)
SampleProject.Web (holds controllers and views)
I am calling the Service classes from my controllers. The service classes are calling Data classes and performing the database operations.
I have done create, list and details part. Now I stucked in Edit part. None of the examples (NerdDinner,MVCMusicStore etc) using my architecture. In the provided examples, they are just using built in UpdateModel method which I don't want to use. I want to manually get the model object from my view and send it to my Data layer for update.
View 1 Replies
Nov 3, 2010
i have a base controller that looks like this:
[Code]....
and a contact model that inherits from the base model.
the master page inherits form the base model,
nad the contact page inherits from the contact nodel,
but then i get an error while loading the contact page that it expects the contact model but gets the base model?
View 9 Replies
Mar 13, 2011
I am creating a web page that will pretty much persist - no postbacks - using jQuery.
I'm going to talk to the page with web services.
So I was thinking that when the user first gets the webpage I give them a GUID that they have to pass back to me with every future call to web services.
I'll simply save the GUID in a table in my MS SQL database and by grabbing that record from the db I could potentially get all my user specific data - user id - permission levels - whatever.
I can make the session row expire after like 10 hours - or something like that - so that they don't get the same session tomorrow simply by forgetting to close the browser window at the end of the work day.
..
View 2 Replies
Nov 1, 2010
I have to use cache multiple forms data that will be submitted on last form. I m not getting how to handle cache key as it should be unique. I want to use this key to get and put data in different forms. I considered to use GUID but it is very long to put in query string.
View 2 Replies
Aug 11, 2010
Currently we are using WebFormsMVP to allow better testability in our project. The framework does presenter binding in OnInitComplete and relies heavily on DataBind expressions e.g.
<asp:Label Text="<%#Model.FirstName%>" runat="server" />
As i understand above article this would put Model.FirstName into ViewState. Because databinding happens late during page lifecycle when viewstate tracking is already enabled.
One option would be to disable ViewState altogether. Are there any other? Remeber, we can't use OnInit or OnInitComplete, because OnLoad is the first event presenters can handle.
View 1 Replies
Apr 4, 2010
There have been many question on managing EntityContext lifetime, e.g. http://stackoverflow.com/questions/813457/instantiating-a-context-in-linq-to-entitiesI've come to the conclusion that the entity context should be considered a unit-of-work and therefore not reused. But while doing some research for speeding up my database access, I ran into this blog post...Improving Entity Framework PerformanceThe post argues that EFs poor performance compared to other frameworks is often due to the EntityConnection object being created each time a new EntityContext object is needed.
To test this I manually created a static EntityConnection in Global.asax.cs Application_Start().
I then converted all my context using statements to
using( MyObjContext currContext = new MyObjeContext(globalStaticEFConnection)
{
....
}
This seems to have sped things up a bit without any errors so far as far as I can tell.But is this safe?Does using a applicationwide static EntityConnection introduce race conditions?
View 3 Replies
Apr 19, 2010
I am part of a development team building a new ASP.NET 3.5 web application. Two of us are C# coders, and the other is a VB.NET coder.
I know that we can mix languages on a per-project basis, and one can build classes in one language that inherit from classes written in the other language in a different project (which we are already doing), but I can see us getting into a situation where we might well end up with cyclic dependencies between our various project DLLs.
Other than simply having a high number of projects (more seperation of concerns into more libraries), how have you managed this situation on your own projects?
Note - I believe this question to be different enough from the only similar match I could find (this one) on the basis that we are not wanting to use different languages in order to take advantage of their specific features per se, but rather to make use of what developer resource is available to us (i.e. one dev just happens to be VB.NET only).
View 3 Replies
May 28, 2010
With VS2010's mandate that web.config be included in the project, how do we allow everyone to keep their own custom config file without getting into source control problems?
Previously, we would simply leave web.config out of our project, allowing everyone to keep their own local version of web.config on their machine. We moved to VS2010, and it is now forcing me to add web.config to my project in order to run debug mode. Because our project is linked to TFS, it automatically adds web.config to source control and tries to maintain it that way.Is there a way to run in debug mode without including web.config in your project? Or is there a better way to manage config files?
View 6 Replies
Feb 8, 2011
I'm having an issue with my hosting provider (winhost.com). My app is built on ASP.NET 4 MVC 3. Up until a few days ago, everything was running fine. All of a sudden I've started getting 503 errors when trying to access my site (wikipediamaze.com). It doesn't happen all the time, just most of the time.
When someone starts playing the game a request is made to wikipedia.org to get the contents of the page for the current step in the puzzle. Basically I'm screen scraping wikipedia.org, injecting some html and then displaying the results. All of my web requests are closed immediately after receiving the data.
What winhost is telling me is that there are connections remaining open and causing any additional requests to the site to get the 503 Service Unavailable Error. What I can see from my end is that only 1 request is ever allowed to be made to wikipediamaze.com at a time. If you keep refreshing the page you'll eventually get the HTML but all subsequent requests (css,images,js) all get the 503 error. Even pages that don't ever call out to wikipedia.org.
If it was an issue with connection throttling in IIS, do both incoming and outgoing (requests made internally) fall in to the same bucket? If I'm sure all of my connections are being closed (and I've never had this issue before) what else could cause this?
View 1 Replies
Dec 1, 2010
how I can create a Database in SQL Express, then add tables and columns .. etc to the Database.
On PHP & MySQL I use to go into PhpMyAdmin and do that all there ! However with SQL Server Express and Visual Studio 2010. how to do it.
View 3 Replies
May 27, 2010
Say I have this entity with a lot of attributes. In the input form I have decided to implement a wizard control so I can collect information about this entity in several steps. The problem is that I need to collect information that has been modeled has many to many relationships. I am planning to use a telerik gridview to manage this (add/edit/delete), the problem is where do I store that data since the entity in a insert form is not created on the database yet. OK so I can store all that info in temporary lists residing in the viewstate, waiting for the final submit where I dump all that in the DB, but one of the steps I am collecting files...now storing files in the viewstate is out of the question, same as as storing them in the session...I have been thinking of implementing in a way that the user has to submit some info first (say first 3 steps), commit the data to the database creating the parent entity and then start inserting all the childs entities...but this will get weird as it's confusing since on the first steps you not saving the data to the DB and on the next ones you are commiting directly...
View 1 Replies
Mar 31, 2011
I've put my site online and I'm looking to add/change user membership. From Visual Studio, I can access the Website Administration Tool WSAT and it's great if you just want to add users manually. Is there a similar way to change users once the site is hosted on a remote server?For the moment, I change the user information through the WSAT and re-FTP the mdf file; it's pretty painful.
View 1 Replies
May 17, 2010
In this case I have a system where a user logs in, they get a dashboard and they can see all their related projects. The user can click on the project and open it. (ie /View/79) The problem the user can also just type /View/68 which they are not supposed to be able to view.
Obviously I am aware of how to filter my data, but this application has many many lists of data and it all needs to be scoped to data that user has been allowed to see. I can insert a plethora of joins and wheres in all my queries but.. it's a lot of work and a bit convoluted.So I was wondering what strategies other had used for filtering data based on the user scope.One approach I was thinking of was to extend my user-role-permission model so "permissions" could be assigned to various entitites (like projects). This way, rather than doing a series of joins etc to see confirm a user has been assigned to a project, my join is just onto the EntityPermission table to confirm the user has PermissionX (like: CanView) on that entity. I could either maintain a seperate M2M table for each entity i need to restrict or something a bit more general (but without referential integrity).
View 3 Replies
Mar 17, 2011
I am doing a registration form where the user enters his account information, and some other misc. information.
The misc. information are stored in another table and hence has its own model.
How do I have the model binder creates 2 model, or should I have one combined model?
View 1 Replies
Jan 21, 2011
I have been searching for this answer and can't seem to find anything, but with EF4 I want to create a base model and put in our 'foundation' and any new project we create if we need to add custom tables to that sites db is it possible to add a model with just those specific tables and link it to the model in our 'foundation' I can't seem to find a good resource on something like this and this seems to be like it would be a normal thing to have a reusable base model and a separate one for any one off's
View 1 Replies
Mar 28, 2011
A friend and I manage a large website for a company. The site is build using Visual Studio 2005 and is a series of nested web applications run inside a master application employing nested master pages. Currently we have to manually move files around folders and FTP them to various servers and I am looking for a way to be able to manage the deployment end of the site in a more automated fashion. I'd like to be able to work on my local version of a project and once I'm done be able to hit one button and publish the site to our internal testing server and then when testing is complete hit another button to deploy it to the live web servers. Right now we have to manually navigate the windows folders and copy pages, css files, images, swfs, etc and FTP them manually. The driver for this is that we have a new junior develop starting and want to remove the manual aspect in advance of him starting.
View 1 Replies
Mar 14, 2011
When developing large application using ASP.NET (MVC or classic, doesn't matter), especially in large team, it is easy to produce a lot of messy, non-traceable CSS definitions. After some time we can end up not knowing why particular definition exists and what is its real effect considering style inheritance and cross-browser differences. Needless to say, changing anything in that mess is a risk and there are hundreds of ways how small change could affect the system.
I know some solutions to organize CSS stylesheets better, like predefined CSS "frameworks" or DotLessCss engine, but I still find it quite hard to cope with CSS as there is no such relationship between HTML markup and CSS styles like i.e. between interface and concrete class in C# code. I know this is by design to make presentation separate from the structure, but I believe it might be useful to have such a correspondence at development level.
Ideally, I need something that can enforce the team not to make messy CSS or be able to clean that mess up automatically. Do you know any resources that may help me, or any guidance how to manage my CSS definitions easily? Let me ask for something a bit different:Despite of my several years of web experience, I believe I would feel much more confident if some of my CSS could be moved into C# code, the same way as some of HTML generation is done by MVC HTML Helpers. It saves me writing a lot of unnecessary markup, still allowing to do so if needed. And it is more unit testable, easier to refactor using tools like ReSharper etc. I don't need mergers and compressors of my CSS, I would like to be able to manage my CSS at declaration level. Maybe there are some tools like that I'm not aware of, or maybe that idea is just wrong and wouldn't be useful?
View 3 Replies
Jun 18, 2010
My lecturer insists that a web site should NOT have a static SQL connection as its not good practice (didn't explain why) but then I thought that if one makes instances of an SQL connection everytime I want to save, delete or edit then surely thats a bottleneck as I would need to everytime establish a connection and then do the save process. From what I have read online, the process of establishing a connection to the server is the longest (about 5 to 10ms)...
How would one manage their SQL connection. At the moment I do something like:
[Code]....
View 1 Replies
Dec 20, 2010
Now i am developing web application, i wanted to be like a CMS but not with all the bells and whistles of a fully blown CMS system. To explain the idea, it is a classifieds ads site were users can log on and add their own ads or browse other users' ads. What i want to be able to do is to have full control on the application without having to write any line of code. I mean, after the application is launched, i want to be able to add / delete ad categories, change dynamic content on the site (like banners, polls and so on).
I managed to create a control panel for myself where i can edit and manage the ad categories (after all it's a data repeater bound to a database and rendering to an ul list containing the categories). My question now is: i am using Master / child pages design, I have some content that's on the Master page and other on the child pages (by content i mean those plugins that are frequently found on websites like polls, news tickers, stocks...etc). Using the Master / Chile paradigm: how can i control the visibilty of those controls through my control panel?
add labels for those controls and control their content from the backend database together with a boolen indicating their visibility. But the problem is that: how can i determine which page is serving this content currently. Like for example, a news ticker on the addad.aspx child page but not on viewads.aspx child page.
View 1 Replies
Mar 4, 2010
What is a good approach to managing a debug and release connection string in a .NET / SQLServer application? I have two SQL Servers, a production and a build/debug and I need a method of switching between the two when my ASP.NET application is deployed. Currently I simply store them in the web.config and comment one or the other out, however that is error prone when deploying.
View 6 Replies
Jun 2, 2010
Need ideas on how to do this. I have a page where I'm adding a new object.This is a row in a db table. This object has a list of other objects associated with it.I want to be able to define the sub-objects before adding the new object. Does that even make sense??
I was thinking somehow using the object datasource would be a good way to manage this. That way when I add the object, just loop through the object datasource to get the sub-objects to add. How would I achieve this with the object datasource, or am I even going about it the right way?
View 5 Replies
Jan 30, 2011
I finally got a GridView to display MySQL Data. Now however I need:1) To edit the way the data is displayed. When my DateTime is grabbed from the MySQL Db, it is displayed like so { 22/01/2011 15:45 } but really I need it like so { 22 Jan 2001 - 15:45 }.2) To Enable Edit, Delete andUpdate of each row of the data. when I go in design view and click on the gridview, I don't get them options, where as on SQL Server 2008 I did.I did some google searching on editing the way a date time is presented, but all I got were results for the function DateTime.Now ..etc which is not what I'm after really.
View 17 Replies
Jan 31, 2011
have a question related to sitemap ........i have a pool of websites which are same in function but different in css and format ..every site in that pool different from each other in terms of information so each site in the pool would have different sitemap.xml but the problem is how would i know that the Google crawler or other search engine crawlers are picking the right sitemap ... ?is there any place where i can identify that sitemap-abc.xml belongs to abc site and sitemap-xyz.xml belongs to xyz site ? ll the xml are put in one folder only difference in between them is there names ..
View 1 Replies
Oct 19, 2010
I am currently working on a website which allows a prospect to generate a quote and purchase a policy. After they submit their payment the application should generate a policy number.
I was given a block of policy numbers to use incrementally. For this example, let's say 0100800 - 0100999. If I have two or more people who decide to purchase a policy at the same time, What are some best practices/algoithms to make sure I don't generate the same policy number for two or more people?
It's also possible that after the last available policy number 0100999, I may be given another block of policy number for example 0222100-0222399.
View 7 Replies