Html.DisplayFor DropDownList - Selected Value Is Not Set?

Oct 21, 2010

Im using asp.net mvc 2. I have a model Supermodel that consists of 2 models TestModel1 and TestModel2. In SuperModelView Im doing the following thing:

<%: Html.DisplayFor(x=> x.TestModel1, "TestModel1Template") %>

Its working just fine, except for the fact, that dropdownlist is populated but selected value is not set.Im using the following code for a dropdownlist in my template:

<%: Html.DropDownListFor(x=> x.Property1, (IEnumerable<SelectListItem>)ViewData["MyDDLList"], Model.Property1) %>


and its not setting the selected property. I put the code below to SuperModelView, that calls <%: Html.DisplayFor To populate the template and it works just fine.

<%: Html.DropDownListFor(x=> x.TestModel1.Property1, (IEnumerable<SelectListItem>)ViewData["MyDDLList"], Model.TestModel1.Property1) %>

UPDATE: I`ve tried to investigate the issue, but something is totally wrong. I can share the whole code, not sure where to put it, here or attach with separate files.

@Darin, what other parts should I share, or just share the whole model view and controller files?

View 1 Replies


Similar Messages:

MVC :: Html.DisplayFor In An Iterator?

May 12, 2010

I need a way to show the display for an element in my list view like so:

[Code]....

Would it be possible to pass in a model to the DisplayFor method?

Maybe a syntax like this:

public static MvcHtmlString DisplayFor<TParentModel, TModel, TValue>(this HtmlHelper<TParentModel> html, TModel model, Expression<Func<TModel, TValue>> expression);
<%: Html.DisplayFor(item, i => i.BarBaz) %>

View 2 Replies

Html.DisplayFor () In .Net MVC For List Of Items?

Jan 13, 2011

I have a list of Key/Value pairs. basically its a List where ViewModel is a custom class of the form

public class ViewModel
{
public String Key { get; set; }
public String Value { get; set; }
}

In the View i would need to render Label and Textbox for Key and Value respectively.Im trying to use Html.DisplayFor() however it goes with model and only displays the properties of the model and not the list.I would like to achieve something of the format

<% foreach (var item in Model) { %>
<tr>
<td>
<%:Html.Display("item")%> [code]....

View 1 Replies

MVC :: HTML.DropDownList - Get Item Selected?

Jan 14, 2011

so I have the following html.dropdownlist;

[Code]....

how do I get the value/item selected in my controller?

View 3 Replies

MVC :: Html.DropDownList Not Setting Selected Value?

Feb 22, 2011

I've been all over the Internet looking for an acceptable solution to this issue, but didn't find one, so hopefully I'll have more luck here. I've got a Html.DropDownList control in my application that pulls in a set of values from the database. That works just fine. However, I want to set the selected value in code, which has never worked correctly. This is, in my opinion, one of the worst implementations of Html helpers in MVC. Here's the culprit:

[Code]....

OK, it takes in a list of statuses and gets the text/value options set without a problem, but doesn't ever render the selected value on the option with a value (ID) of "5". I've stepped through the code as it is assigning these values, and it
does set the value of that option to select = true, but the rendered html doesn't reflect this. I recall something about this helper using the Model to set its selected value, but why will it not allow the value to be explicitly set? Even better, if for some reason explicitly setting this in code isn't going to work, why allow it as viable code, and just silently fail? I'm all for this coding by convention approach MVC has taken, but when the convention is explicitly overridden in code, the code should prevail, I would think.

View 1 Replies

MVC :: Access Selected Item's Description In Html.DropdownList?

Feb 7, 2010

I have a MVC dropdown list (Html.DropDownList) with list of Movies populated. I want to retrieve both Title(value field), Description(Text field) when I perform the form Submit. I can access the Title(value field), but I can't access the description. My code sample is below.

[Code]....

public string CinemaName { get; set; }

View 4 Replies

Asp.net Mvc2 - DisplayFor Need Iteration-like Context?

Jan 15, 2010

In my app I have a criteria builder section that's built using jquery and is pitched back to the controller in a form post and picked up as IList by the model binder as suggested in Phil's post here: http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx A really simple way that I'm persisting the criteria across posts is re-delivering the IList object to the view. I'm using a DisplayFor() template for this object, but because it's a list I need to know the index # inside of the template.

View 1 Replies

C# - Disable Or Enable 2nd Dropdownlist In Aspx Based On Selected Choice Of The 1st Dropdownlist Box

Apr 15, 2010

I am having a problem with disabling DropDownList based on the chice of 1st DropDownList, there is no post back occuring, and it is a template based web app here is the current code:

<script type="text/javascript">
$(function() { var dropDownList1 = $('#<%= ddlUserType.ClientID %>');
var dropDownList2 = $('#<%= ddlMember.ClientID %>'); dropDownList1.change(function(e) {
if ( jQuery("#ddlUserType").val() != "ETOC") dropDownList2.removeAttr('disabled'); e.preventDefault();
else
dropDownList2.removeAttr('enabled'); e.preventDefault(); }
} );
</script>

what is happening now is page is blank and if I remove the above code everything shows, where I am going wrong. here is the plain and final javascript code which worked:

<script language="javascript">
function CheckDropDownState(lstbox)
{
if (lstbox.selectedIndex == 3) { document.forms[0].ddlMember.disabled = 1; }
else { document.forms[0].ddlMember.disabled = 0; }
}
</script>

and thew .aspx code: <asp:dropdownlist id="ddlUserType" runat="server" onclick="CheckDropDownState(this);"></asp:dropdownlist>

View 2 Replies

Web Forms :: Display All Items In Child DropDownList When ALL Is Selected In Parent DropDownList

Sep 6, 2012

protected void DDLzone1_SelectedIndexChanged(object sender, EventArgs e)
{
BindDistrict();
}

[Code]......

here when i click on ALL item from ddlzone1  it just "ALL" item in ddldistrict

i want when i select "ALL" item from ddlzone1 in ddldistrict14 show all data from database

View 1 Replies

Disabling Dropdownlist Inside A Gridview Based On Value Selected On Another Dropdownlist?

Jan 11, 2011

what i m trying is i hav two dropdownlists inside the gridview... namely say ddonsiteoffsite and ddhours... now what i want is if the selectedtext of ddonsiteoffsite is "onsite" the ddhours should b disabled... i tried the code snippet but ... its not disabling the ddhours... can someone help me please..

<asp:TemplateColumn HeaderText=" OnSite/OffSite" >
<ItemTemplate>
<asp:DropDownList ID="ddOnsiteOffside" runat="server" onchange="ToggleOnOff(this)">
[code].....

View 2 Replies

Data Controls :: How To Fill Second DropDownList When First DropDownList Value Is Selected

Dec 17, 2012

I am having a 2 dropdown list, in the first dropdown I have 3company names,for each company I am having separate tables,every table have a empcode, if the user select the  company name in the 1st dropdownlist, as per company selected the 2nd dropdownlist it will fill the  list of employee codes as per the selection..

View 1 Replies

Web Forms :: Display Selected Value Of One DropDownList In Another DropDownList On Different Page

May 7, 2015

I have two pages manager and user both have drop downs as 

Week, Months and Years.

User have to enter some data week wise for each months and Manager have to approve that.

To Approve manager select months and week from dropdown on his own page and then navigate to User page.

How does I should bind the drop down so that if manager select 1st week from it's page and goes to view link of user then in drop down of user selected value shold be the same as selected by Manager on his own page.

View 1 Replies

MVC :: Avoid Line Break For MvcHtmlString Returned From DisplayFor Label Extension?

Jun 21, 2010

i use the Html.LabelFor method for displaying the property names and Html.DisplayFor for the property values of my model.

Unfortunately i cannot use the following format:

Title: value...
Description: value...

since the LabelFor method inserts a line break, so the result returned is like:

Title

: value...

Description

: value

How could i get rid of the extra line break?

View 6 Replies

Should The Selected Index Or Selected Value Be Used To Set A Dropdownlist

Nov 26, 2010

I am binding months to a list 0-13 items default selection is 0 months duration, and years 0-8 items and 0 years is the default selection.As I know there are always going to be 12 months in a year, I could use selectedvalue or selectedindex without any perceived problem. Is there a reason why I should not use either/or of the two properties to select a list item?

View 2 Replies

DropDownList / Based Off What Is Selected As The Dropdownlist?

Oct 6, 2010

I am trying to make a simple dropdownlist.Based off what is selected as the dropdownlist, I want it to open a new webpage.

For example:

Here is the dropdownlist - If they select team1, I want it to open up webpage /team1.aspx If it's team2, team2.aspx and so on.

<form id="form1" runat="server">

View 2 Replies

MVC :: Dropdownlist Is Accepting "selected" But Isn't Rendering That Option As Selected

Sep 30, 2010

I thought this would be pretty simple, and in fact it's working on another dropdownlist on the same View, so I'm hoping I missed something very small that is easy to fix. Here's my code:

[Code]....

When I step through the code, the 'Active' option's 'Selected' property is being set to true. That's expected. But when the View renders, it's not selected and a look at the page source shows that the selected property isn't set. What is the problem here, and what's the solution?

View 10 Replies

Dropdownlist - "Cannot Have Multiple Items Selected In A DropDownList.&quot?

Apr 29, 2010

how i handle this problem..Its in hidden filed.

Server Error in '/DentalClaimPrjt' Application.

Cannot have multiple items selected in a DropDownList.

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.Web.HttpException: Cannot have multiple items selected in a DropDownList.

Source Error: [Code]....

Line 85: function openPopup2(did)
Line 86: {
Line 87: var hdnClm1 = document.getElementById('<%=hdnCliamid.ClientID%>').value;
Line 88: window.location="Form.aspx?DeleteRSPid=" + did + "&Editid="+ hdnClm1;
Line 89: }

Source File: d:DentalClaimPrjtForm.aspx Line: 87 Stack Trace: [Code]....

[HttpException (0x80004005): Cannot have multiple items selected in a DropDownList.]
System.Web.UI.WebControls.DropDownList.VerifyMultiSelect() +106
System.Web.UI.WebControls.ListControl.RenderContents(HtmlTextWriter writer) +124

View 2 Replies

Second Dropdownlist Changes When First Selected?

Feb 7, 2010

Now I'm stuck in changing the second dropdownlist. For example, first dropdownlist- select 2, second dropdownlist will change from 1,2,3,4 to 2,3,4,5,6. Other than cascading dropdownlist, it there anyother methods?

View 1 Replies

Getting The Selected Value Of A Dropdownlist

Dec 16, 2010

I have an issue getting the selected value of a dropdownlist.

My view source looks like this:

[code]....

The problem is that Request.Form["DivisionesLists"] returns "1,1" instead of just "1" (which is the actual selected value of the dropdownlist).

View 2 Replies

VS 2008 Put Selected Value In DropDownList?

Aug 29, 2010

Is it right way to get the selected values in DropDownList

Code:
cmbType.SelectedValue = reader.Item("HeadName")
or Please suggest the right way

I m getting the below error on this line

'cmbType' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value

View 9 Replies

C# - How To Get Selected Value From Dropdownlist Using Javascript

Mar 9, 2010

i am populating country dropdownlist from database.i need to select a value from dropdown list and assign it to textbox by using javascript.

Code:

var textboxId = document.getElementById("txtCountry");
var dropdownListId =document.getElementById("ddlLocation");
var e = document.getElementById("ddlLocation");
var strUser = e.options[e.selectedIndex].value;
document.getElementById(textboxId).value = strUser;
document.getElementById(textboxId).focus();

View 3 Replies

MVC :: Set Selected Value In DropDownList Not Showing

May 30, 2010

On an action I have the following:

[Code]....

The days list shows fine but the selected value is not 2 but "---". Why?

View 3 Replies

Get Selected Value From Dropdownlist After Submit?

May 17, 2010

I populate DropDownList in ASP.NET webforms:

<asp:DropDownList runat="server" ID="salesman"></asp:DropDownList>

users= Buslayer.GetSalesRep(); [code]....

View 1 Replies

Get The Text Of The Name Selected In The Dropdownlist?

Jun 3, 2010

I have a dropdown list where the items displayed in the list are names, and the DropDownList selectvalue is Person_ID.

How do I get the text of the name selected in the dropdownlist and not the SelectedValue?

View 3 Replies

How To Get The Selected Value From A DropdownList Using JQuery

Aug 12, 2010

I have the following code and it gives me the text but not the value. What is wrong and how do I fix it?

[code]....

View 1 Replies







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