C# - MVC Handle Drop Down Boxes That Are Not Part Of The Model?

May 21, 2010

I have a small form which the user must fill in and consists of the following fields.

Name (Text)
Value (Text)
Group (Group - Is a list of option pulled from a database table)

Now the Model for this View looks like so,

public string Name { get; set; }
public string Value { get; set; }
public int GroupID { get; set; }

Now the view is Strongly Typed to the above model.

What method would one use to populate the drop down list? Since the data is not contained within the Model (It could be contained in the Model) should we be using Temp/View data? A HTML Helper? What would be the ideal way to achieve this.

View 3 Replies


Similar Messages:

Handle A Model With A Lot Of Drop Down Lists In Mvc?

Dec 8, 2010

I have a model with a LOT of foreign keys. Right now, I'm populating view data:

ViewData["fieldname"]=new selectlist(entityframeworkmodel.foreigntable.ToList(),"fieldkey","valuefield");

I really don't like this approach. For one thing, I'm supposed to just name the field the same thing and trust that it will get stored in the model. I don't really understand how that works but it's a little worrisome.

Secondly, my code is now a bit of a mess.

//Address drop downs
ViewData["AddressType"] = new SelectList(ent.tblAddressTypes.ToList(), "AddressID", "AddressType");
//Contact Drop Downs
ViewData["ContactTitle"] = new SelectList(ent.tblContactTitles.ToList(), "ContactTitleID", "Title");
//Event

[Code]...

The other issue is I don't see how I can test this. I've written a repository method that just maps the id values from the drop downs into the respective EF objects.

How are other people dealing with this? I do set up these drop downs in a few places, so I thought about putting them in a controller method.

P.S. Kind of thinking about this: [URL]

View 1 Replies

Forms Data Controls :: Space In Text Boxes & Drop Down Lists / Text Boxes Gets A One Tab Spacing?

Jan 20, 2011

Using C# and SQL as the database.I have a page with a gridview and some text boxes and drop down list boxes. A user selects a record from the grid view I query the database and fill the text boxes and drop down list boxes.

Some fields get updated periodincally thus there is no data in those fields in the database until some time.

A strange thing happens.When filling data some text boxes gets a one tab spacing .

View 1 Replies

MVC :: Display Drop Down And Text Boxes Inside A Grid

Feb 2, 2011

I want to display the whole row of the table inside a grid as one row. so I have a table that has First name last name Age scoresInside a Telerik MVC grid I want to display

First Name and the name of the person in the text box, beneath the first name , I want yo display Last name and the name of the person in a text box, same thing with age and I want to display scores in a drop down list box so that users can look at the value and edit at the same time. I only want to display one record at a time.

I can display one record at a time, but i am not sure how to edit the records and show the empty text boxes and drop down list inside the grid.

[Code]....

I tried the above code, but that displays the text boxs in one row. i need to display one text box for name and then directly beneacth it, i want to display lastname and test box and then drop down list box right next to the text box.

View 6 Replies

How To Change The Appearance Of The Items Such As A The Text Boxes And Drop Down Lists

Feb 3, 2011

how i would go about creating the following page.

http://www.lifetick.com/app/#/createAccount//

Id just like to know how to change the appearance of the items such as a the text boxes and drop down lists. And is the the backgroud around the boxes an image?A link to how to do this would be useful if yous cant go into detail on how to do this.

View 4 Replies

Drop Down Menu Float Visible Over UI CONTROL Like TEXTBOX, Select Boxes, And Iframes?

Mar 9, 2010

Issue is Menu is not overlaping or float, above the IFrame i am design the menu with table and Div tag in Usercontrol From and i called Usercontrol from in the Index.aspx.

View 1 Replies

MVC :: How To Pass Data (not The Part Of Model) From View To Controller

Oct 8, 2010

How Can I Pass data(not the part of model) to Controller from View? View Code

[Code]....

View 4 Replies

Web Forms :: Handle Lots Of Drop Down Lists On 1 Page?

Mar 22, 2011

I have a page that has a data grid and about 25 drop down lists.The datagrid displays Name and has an id col not visible. I was thinking that whan the user selects the select link button on the grid to then get all the data for all the ddl and populate the list and select the value or multiple values for that specific name that was selected. Thinking of it seems more like i should populate all the ddl and when a grid name is selected only get the keys for that specifc record and then mark the ddl items per that name. there are lots of ddl and lots of data, im not really sure the best way to proced. Any ideas appreciated.
I have a table with id typeId and Name that contains all of the data for the drop down list (different types of service providers , (plumbers, elec)I was thinking of selecting everything from that table and then in the page applying a filter by service provider type and using that to populate the ddls.

View 2 Replies

MVC :: Multiple Forms On The Same Page / How To Handle (including Validation From Model)

Jan 12, 2010

It should be simple; although I'm having a hard time to figure out the best way to do it. I've MVC2 pages with multiple forms on the same page having different functionalities.

What's the best way to handle this; including the MVC2 way of validation from the model?

View 2 Replies

MVC :: Show A Model Item As A Drop Down List Or Radiobuttonlist?

Aug 12, 2010

I am working with a model which has the following, basically a Project can have a score between -5 and 5 and I'd like to show a dropdownlist of the available options, i.e 5,4,3,2,1,0,-1,-2,-3,-4,-5.

[Required(ErrorMessage = "Score is required")]
[Range(-5, 5, ErrorMessage = "Score must be between -5 and 5")]
[DisplayName("Score")]
public double Value
{
get { return value; }
set { this.value = value; }
}

What would be the best way to accomplish this using a dropdown list and how can I make the score of 0 the
default selection?

View 3 Replies

MVC :: Creating A Generic Template Writer That Can Handle Drop Downs And Option Lists?

Sep 20, 2010

If I have a the following model

[Code]....

And the following generic control template writer (which would have to be extended appropriately)

[Code]....

I would like to be able to add an attribute either builtin or something I create, such as

[Code]....

The generic template writer would then automatically create a Select box instead of a textbox for this item, and populate it with the list I have passed.

There may need to be another property set to have it write option boxes or radio buttons.

The question has two parts: (1) Is this an appropriate metaphor? and (2) Can you point me to an example that does this or to an appropriate metaphor.

What I want is a generic control writer that looks at the type of the object, writes the appropriate html, and a way to pass in external data for things like lists and enums.

View 3 Replies

Forms Data Controls :: Develop A Custom Data-bound Control Which Will Contain, Few Text-boxes, Drop-down Lists And Labels?

Mar 24, 2010

I need to develop a custom data-bound control which will contain, few text-boxes, drop-down lists, labels, and other standard web-server controls. And, I want to be able to load this control from a web page on button click. When the user enters any data to any of its child controls, i should be able to save, and also retrieve when the data-bound control is loaded again. Also, the data in the child control should retain their value on postback. What approach should i follow?

View 7 Replies

Model View Presenter - How To Show Selected Item In A Drop Down List

Jul 23, 2010

I'm using Model-View-Presenter framework. When Loading a page, I'm having trouble setting the selected item that came from the Database.

In view, I know I need:

protected void ddlStatus_SelectedIndexChanged(object sender, EventArgs e)
{
presenter.DdlStatusSelectedIndexChanged();
// what should this pass?
}
Then in Presenter:
public void DdlStatusSelectedIndexChanged()
{
view.DdlStatus = ???
// Should I pass the SelectedIndex?
}

I also think that part of my problem is that DdlStatus I have as a List.

Interface:

List<StatusDTO> DdlStatus { set; get; }

The best I found is here (but needs formatted!) ---> [URL]

View 2 Replies

Web Forms :: Custom Validator Validates Three Text Boxes And Give Errorto Fill The Boxes

Apr 20, 2010

I have a custom validator which validates three text boxes. my code is,

[Code]....

I fill in all the three textboxes.it still gives me the error message to fill in all the boxes and does not submit the page even when all the three boxes are filled.

View 3 Replies

MVC :: EF - Nullreferenceexception In View. Handle Non Existing Object References In View Model

Mar 15, 2011

I have an entity object as model input in my view. Not sure if it's the best approach, but I use the object references to get values from a related object.Let's say I've got a car entity and a manufacturer entity.Here's how it would look in my view

[Code]....

I've get a nullreferenceexception where the car entitity does not have a reference towards manufacturer. I'd like to output a " " if no manufacturer exists.

View 4 Replies

MVC :: How To Pass All The Option List Item From The Drop Down List To View Model

Nov 10, 2010

I have a requirement in my application that, while saving the application, need to get all the value from drop down list and pass it to the view model. But application should not allow the user to select more than one item from drop down list manually, ie, only one value at a time. My view model is like ...

public class ListManagement
{
public IEnumerable<selectListItem> InactiveProduct { get; set; }
public string[] InactiveProductSelected { get; set; }
public IEnumerable<selectListItem> ActiveProduct { get; set; }
}

[code]...

View 3 Replies

DropDown List Boxes And Get The Value Of It Both Boxes?

Mar 26, 2010

I have two dropdown list boxes I select the first one and I get the index value of what i selected say item number 2,Using that indexvalue I would like to acccess the second dropdown box and get the value of it Both boxes will have the same amount of items in it.

View 4 Replies

Sharepoint Proxy Web Part - Configure The Web Part To Point To An Existing Web App

Feb 17, 2010

We have several asp.net web applications we've built and we also want to embed them into various sharepoint pages. We need to have them look like standalone applications when viewed in their own pages, but also have them look like they fit within the sharepoint page when embedded. We are doing this currently with IFrames and it works ok, but I'm wondering if there is some sort of proxy web part where we can configure the web part to point to an existing web app and it will proxy the contents through from the web app into the sharepoint page removing the need for an IFrame. Possible?

View 2 Replies

Web Forms :: How To Get Values In Oultook From Database To Part Ab And Cc Part C And D

Sep 3, 2012

I have four columns in database. Consider it as a,b,c and d. I'm trying to place a and b column values in TO part and c and d column values in CC part in outlook. a,b,c,d contains six digits numeric values. I just need to place a and b columns values in to and c and d values in cc part on click of a button.

View 1 Replies

Create Text Boxes Dynamically Want To Bind Autosuggest With The New Created Text Boxes?

Feb 3, 2011

i can use auto-suggest with the text box txtCode like this...

as_jsonReportingTo = new bsn.AutoSuggest('<%= txtCode.ClientID %>', optionsRe);

Now I will create text boxes dynamically, i want to bind autosuggest with the new created text boxes. What should I do?

View 1 Replies

C# - SharePoint Web Part Gallery Details Of Each Web Part

Mar 2, 2011

When using SPWeb.GetCatalog(SPListTemplateType.WebPartCatalog), it returns an SPList which of course contains a SPListItemCollection of the web parts in the web part gallery. When looping through the items, is there any easy way to get properties of the web parts? Such as AllowClose, CatalogIconImageUrl, etc... I know I can probably accomplish this using the listItem.OpenBinaryStream etc and loading the xml of the .webpart file, but I wondered if there was an easier way to do this.

View 1 Replies

Difference Between SharePoint Web Part And Web Part?

Nov 24, 2010

Whats the difference between a SharePoint web part and an ASP.NET web part. I found very less information describing the differences.

View 1 Replies

Web Forms :: Want To Website Url In Web Part And Open Website Like I Google In Web Part Zone?

Apr 9, 2010

I m new in web part tools in asp.net, i create a simple page using web part tools, but now i want in my web part zone too open a web site like I Google..

when u use i google there is a functionality to open a web site in web part zone.

View 2 Replies

MVC :: Store Model In Separate Class Library- Pass Model Objects?

May 19, 2010

I'm building an MVC 2 RTM app, and I want to be able to share my model across applications. I'd *like* to be able to implement it like:ASP.NET MVC2 app (holds Views and Controllers)Class library to hold Model(s)WCF app to handle the data transactions with the models via different data stores across apps I had the MVC app working fine, but I wanted to abstract the data stuff and be able to work with the model across apps through the WCF site, so I created a class library project and moved all of the Models classes into that and set-up a WCF app, then added project references to the MVC and WCF apps that point at the class library. The idea was I can create services that take and return objects from the model via method calls across apps. It appears that everything's wired up correctly in the MVC project, so I'm passing the objects stored in the Models class library between controllers and views and everythig is compiling just fine, but for some reason the data is not being passed back from the views to the controller on POST -- all of the properties in the classes are null or empty.

When I debug the app, I can see that the values are stored in the model data dictionary but not the model object itself. What am I doing wrong? Am I on the wrong path, or missing something obvious (to some)?

View 2 Replies

MVC :: Access Model Validation Inside Custom Model Binder?

Sep 1, 2010

Is it possible, inside a Custom Model Binder, to fire "something" that "says" the value is invalid so it gets handled by validation part?

Basically, I am getting an exception when the value for the property is invalid.

View 1 Replies







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