MVC :: Proper Pattern For List Of Reusable Controls?
Aug 26, 2010
Say you have a for loop which renders a bunch of the exact same control. This is probably done with RenderAction or RenderPartial.
What is a way to ensure that each of these controls in the list gets wrapped in a div with a unique ID?
View 2 Replies
Similar Messages:
Jan 15, 2010
I am trying to assign values I've gathered from a JSON feed to my own type, a class in which I have defined certain fields (properties) to put the JSON elements into, plus elements that are derived from a RegEx pattern matching process. This will then allow me to access the object using LINQ, as I am using a List to hold my objects. There is a foreach loop in my code that loops for each match that my RegEx method finds. I am only interested in the parts of the JSON feed where there is a match. So my own defined class is as such:
//simple field definition class
public class TwitterCollection
{
public string origURL { get; set; }
public string txtDesc { get; set; }
public string imgURL { get; set; }
public string userName { get; set; }
public string createdAt { get; set; }
}
And then I want to populate List in the RegEx Matches loop:
foreach (Match match in matches)
{
GroupCollection groups = match.Groups;
var tc = new List<TwitterCollection>()
{
origURL = groups[0].Value.ToString(),
txtDesc = res.text,
imgUrl = res.profile_image_url,
userName = res.from_user_id,
createdAt = res.created_at,
};
}
The code will then go on to extract and sort the results via Linq to Objects. But compiler won't actually let me create my var tc = new List<TwitterCollection>() because: 'System.Collections.Generic.List' does not contain a definition for 'origURL' ... even though I have defined it. It does not flag an error if I simply write new TwitterCollection but then how do I refer to this in my Linq expression later on??
View 3 Replies
Oct 13, 2010
We have an ASP.NET MVC site that uses Entity Framework abstractions with Repository and UnitOfWork patterns. What I'm wondering is how others have implemented navigation of complex object graphs with these patterns. Let me give an example from one of our controllers:
[code]....
It's a registration process and pretty much everything hangs off the POCO class Person. In this case we're caching the person through the registration process. I've now started implementing the latter part of the registration process which requires access to data deeper in the object graph. Specifically DPA data which hangs off Legal inside Country.
The code above is just mapping out the model information into a simpler format for the ViewModel. My question is do you consider this fairly deep navigation of the graph good practice or would you abstract out the retrieval of the objects further down the graph into repositories?
View 2 Replies
Feb 23, 2010
Does anyone have a working pattern for converting a GET-POST-GET pattern to asny?
I'm encountering the following issues:
1. You cannot mix Sync and Async action methods SubmitForm(), SubmitFormAsync(bool? confirm), SubmitFormCompleted() ... (because the resolver gets all confused ... it doesn't use the HTTP verb to decide who to target. BTW: I think that's poor design, or a bug)
2. Renaming the get method name to something else eg: SubmitFormConfirmation(), SubmitFormAsync(bool? confirm), SubmitFormCompleted() would be very awkward if it works ... because you have to doctor the <form markup to specify an action name.
3. You cannot give them all async names SubmitFormAsync(), SubmitFormAsync(bool? confirm), submitFormCompleted(), because the call just keeps malfunctioning. It sometime even behaves as if you are requesting a delete of something.
Can someone give an insight from an actually working sample.
View 5 Replies
Aug 21, 2010
Now that the next version of ASP.NET MVC is being prototyped and previewed (ASP.NET MVC 3 Preview 1 came out a couple of weeks ago), I wonder if we should call the attention of the Core Dev team (S Hanselman, Phil Haack and all) to this "feature."there a easy/non tacky way of associating subdomains → areas?Something like:
[URL]Also, whats the best accepted design pattern in implementing PRG pattern in ASP.NET MVC? I guess it should also get some official loving in MVC 3.
View 2 Replies
Mar 16, 2010
I want to build a reusable library of User Controls.
I found this article:
[URL]
While it works for me, but I find it a bit cumbersome to implement, expecially for future maintenance.Also, I noticed that if you create the User Control with code in separate file, it will not work. In this case, you will not get any error, but, the page where the control in registerted will not show (you will get blank page).Why I am getting BLANK result when I develop the User Control with code in separate file ?I appreciate your recommendation on the best approach to implement a library of Reusable User Controls. Also, I did not like the method of Web Controls, becuase they are difficult to implement.
View 4 Replies
Jan 20, 2010
I'm currently implementing a project using asp.net, c# and the MVP (Model-View-Presenter) pattern. The main purpose of this solution is to deliver a graph to the consumer, to be used by a variety of systems. It is basically a custom graph server.
The view page in this particular case has an MSChart control on it, which has to be dynamically populated and configured based on parameters in the QueryString. This can be as diverse as totally different types of data sets, display modes and so on, using a lot of the properties of the chart control.
Many of these properties are again of types which are particular to the chart control and would require the same dependencies as the chart control itself if they are to be set by the presenter.
I'm trying to figure out the best way to expose the properties to the presenter so it can work its magic.
Should I:
Just expose the whole chart object and live with a system.web type dependency in the presenter project? Make accessor and translation properties for all of the chart control properties so that I don't have the dependency, but add lots of complexity? Other, that I haven't thought of?
To me it seems that it would be against the MVP pattern to bubble a display control up into the presenter, but it seems that trying to map all the properties to DTOs or similar would be a lot of work that would add a lot of complexity, and while the solution would be somewhat more loosely coupled, I'm not sure the gain would be worth it in this case. How would you implement something like this, given MVP?
View 2 Replies
Nov 11, 2010
We have a number of projects and across projects cerrtain forms are duplicated.
Is there a way that I can create one form and reuse it across multiple projects?
View 2 Replies
Nov 30, 2010
I want to set the proper MaxLength on the Textbox in the BoundField
How do I get the DataField from the ContainingField in order to know which field the column binds to (i.e., BoundField).
The Client-Side web form is located at [URL]
Sample snappet reads:
[Code]....
View 5 Replies
Feb 12, 2010
Could someone give me a small example how i can make reusable WebUserControl (.ascx) file.Basically i need to make a employee lookup utility where users enters employee id to get Emplyee information.Once the Emplyee information is available, it is used in various data entry tasks by the page that includes the control.
View 1 Replies
Jan 24, 2011
it is possible to customize the typed view generation process to generate the proper controls based on the fields annotations of a model. For Example I have a Person Model that contains Foreign Keys like CityID,DepartmentID etc. So When i generate a view againt the Person Model it creates textbox's for all the Person fields but i want dropdownlists against FK fields. It Should be smart enough to at least geereate the peroper controls based on the Person's field annotations. How can i acheive that? Has anybody worked on that?
View 2 Replies
Mar 17, 2010
I am having trouble with queries because they are not returning the data needed, and I am having trouble figuring out why because I only am testing with 2 records.First I want a query to return all records for one customer as follows:
[Code]....
There are two records with the customerID of 1, but it only returns one,next I try to return only one record, the AccountPrimary or customer_contacts.IsPrimary, but when I add " AND customer_contacts.IsPrimary = 'True' "at the end of my query it then returns both records, but only one IsPrimary = True and the Other = False. Is it backwards? I also tried another method and it returned 30 of the same record and I only have 2
View 4 Replies
Jan 22, 2011
In ASP.NET web forms we created few user controls (.ascx) which were used in almost all of the projects. I'm not sure how to achieve same in the MVC?
View 2 Replies
Aug 24, 2010
I'm trying to create reusable "zones" but am having trouble figuring out how to give them all unique ids.What I'd like is to be able to create a component which can be put on an mvc page using the usercontrol syntax or using RenderAction or RenderPartial. I want to be able to update these components' content using ajax, so I need someway to reference them by id. However, there is no mechanism in MVC that wraps anything in a div or something like that.
I've learned that if I extend ViewUserControl and put the controls on the page like so:
[Code]....
This way, I can pass the previous ID and put it in ViewData, in case I need it laterThen, I can even go through all my controls on page load event in the master page and get my unique ID and write somekind of register javascript function to the page so that I can do javascript stuff if I want when the page loads.
[Code]....
Is there a more elegant way to do this? I see similar stuff from 'Areas' but never seen an example where someone has put more than one area on a page and then needed to reference them via javascript. This also seems similar to custom templates, but I'm having trouble figuring out how that would work.
View 5 Replies
Jan 14, 2011
I have a FormView with the ItemTemplate and InsertItemTemplate populated. In the InsertItem template, What I am trying to do is that when a user click on the DropDownList and selects the item from the list that they want, it Populates to a TextBox.
I have tried the SelectedIndexChanged event however It does not seem to fire the event.
My questions are;
What would be the proper format for a DropDownList Sender? e.g. I have tried this;
DropDownList ddlProjectYear = (DropDownList)sender;
What is the correct syntax for the FindControl? e.g. and I have tried this;
[Code]....
[Code]....
What would be the correct event that I should be using to have the SelectedValue of the DropDownList show up in the TextBox.Text?
View 5 Replies
Jan 23, 2011
I want have a web application that I am putting together - but I have started to see that some of the things I am writing are repeated over and over, example -
GetDepartments() in the code behind has all the database connections and is linked to a stored procedure.All it does is return Department Names' and Ids', ie then bind them to a dropdownlist.My question is this I have seen Class files - I want to know if I can put this type of information in there and just call it whereever I need it in the site and then bind to whichever dropdownlist I need to?I have had a look around the net and even saw some examples by scott mitchell - but it used datasets (.xsd) files etc and dont want to be using them, plus it was a little over my head. Does anyone know of some good simple examples out there that I can follow, or maybe some examples on here?
View 2 Replies
May 8, 2010
I have a situation where I need to maintain a large number of related integer values in my ASP.Net 3.5 application. The SortedList seems perfect for this purpose. If this were a Windows app I'd just create a class and setup one method to Set values within the SortedList and another one to Get values out of it.
But being a web app, I'm not entirely sure of the best approach to use. Sure, I could just create one method for Set and another for Get but that doesn't seem very "clean".I thought about creating a UserControl without any visual elements but am not sure if that makes sense.How would you go about implementing such a SortedList in your web app?
View 7 Replies
Jan 20, 2010
I have been given the task to create a TAB control ( probably the Jquery tab control) as the company wants the Lazy loading of data.
The tab control should not have fixed items on it. It should be reusable in different projects . So I cannot fix the items in the tab control. Depending upon the project the tabs can change.
Need some great ideas on how I can achieve it.
Note: I am using MVC, VS 2008, C# for my development.
View 2 Replies
Jan 24, 2010
I am trying to write a simple library for MVC2 projects that takes care of user login, e-mail validation, password recovery, logging, etc. Since some of these steps involve user interaction, I need to have Views and Controllers in that project.In MVC2 Preview 2, one could do this by abusing areas (at least, it seems) since they were implemented as different projects. However, in the RC, creating a new area will merely create a subfolder. Since I want to share the base code between applications, that is not an option.I tried to brutally hack the AfterBuild steps into my project files, but that feels like the craziest hack ever.
View 10 Replies
Jun 21, 2010
In the edit template of the listview I have a multiline textbox. But when the row is edited and the template switches to the ItemTemplate, the text is not displaying properly in the associated Label control (missing linebreaks).
I know that the Label control doesn't understand the enter key code, and I need to do a replace on the string. What I have right now is :
[Code]....
View 1 Replies
Feb 23, 2011
I have a Formview where students put their information in such as name, address, etc. The text boxes are bound to my database, so once they are done, they choose to update, and my database is updated with their information. My problem is that the students often use All Caps to enter in their information.
I think I need the StrConv somehow, but I just can't seem to get this done. I've seen where it could be done with text boxes, but not when they were in a Formview using parameters.
View 2 Replies
Jan 24, 2010
I currently have a gridview which I have populated using the following method:
[Code]....
What I am looking for is advice on how to handle coding a proper DeleteMethod to assign to my ObjectDataSource (via my class file). I have been searching through several forums, websites and other media and have been left a little confused. Everyone seems to have their own method, none of which I have been able to successfully adapt to my own needs. Here is some of the functionality that I am looking for:
1.) Delete item using Gridview's delete button
2.) Delete the record from both the datatable (and Gridview Row) and the database that the table was generated from.
3.) Upon deletion, refresh gridview
This may sound simple to many of you, but I need a little advice as to where to start. Any applicable threads, tutorials etc.
View 3 Replies
Jan 20, 2011
I want to build a reusable control which will enable e to perform add/edit/delete operations easily. All I want to do is give the control a datasource and it will handle the rest.
What controls should I use? I want it to be as user friendly as possible.
View 15 Replies
May 15, 2010
In .NET land what would be a good approach for quick prototyping of a concept (i.e. development just on my PC) that could then be extended out to product (users across LAN/WAN), BUT in a fashion that the model/business logic code and data access layer code can be used as is? One thought for example I had as to do:
(a) WinForms with business logic and Entity Framework layer to SQL Server Express on my PC, then
(b) Go then to ASP.net (using the business logic / data library) with SQL Server/IIS
View 2 Replies
Jul 19, 2011
I need to have a section in my website dedicated to viewing and printing reports.I've created a Reports Table (ReportID, ReportTitle, ReportDescription, ReportCategoryID), so I can display a list of Reports on a page.I also have a ReportCategory Table (ReportCategoryID, CategaoryName, Active).So i could have all the categories in a dropdown perhaps(not sure it's the best option)
Then once a selection is made I can display the reports under that category.Clicking on any of them will then display the report or save it to disk.My question is, should I create a Reports Class? if so, can I get a few pointers
View 9 Replies