Tracking Forums, Newsgroups, Maling Lists
Home Submit Tracker Forums
  Advanced Search
  HOME    TRACKER    ASP.NET


Advertisements:










MVC3 - Get Set Of Values Out Of Enumeration


I am having a nightmare with getting a Dropdownlist control to work correctly in my MVC application. I am trying to get a set of values out of an enumeration into SelectListItem which I then present to the DropDownList control as its source. The issue is that I can get the thing to render but the selected value is never set and to top it off when the form is posted the value passed across is 0 instead of the actual value. In the View (Razor Code):

HTML4Strict Code:
@Html.DropDownList("UserRole", new SelectList(Enum.GetValues(typeof(enumUserRoleUserManagement)), user.UserRole), new { @onchange = "submitForm(" + i + ")" })
in the Controller:
Csharp Code:
ViewData["RL"] = new SelectList(userActionsModel.GenerateCombo().AsEnumerable(), "Value", "Text");
And Finally in the model:
Csharp Code:
public IEnumerable<SelectListItem> GenerateCombo()
{
var enumerationValues = Enum.GetValues(typeof(enumUserRoleUserManagement));
var enumerationNames = Enum.GetNames(typeof(enumUserRoleUserManagement));
List<SelectListItem> list = new List<SelectListItem>();
foreach (var value in Enum.GetValues(typeof(enumUserRoleUserManagement)))
{
SelectListItem selectList = new SelectListItem
{
Text = value.ToString(),
Value = value.ToString()
};
list.Add(selectList);
}
//SelectList selectList = new SelectList(list);
return list;}

I have burned soooo much time on this, I will be indebted to anyone that provides a solution.


View 1 Replies (Posted: Feb 23, 2011, 08:37)

Sponsored Links:

Related Forum Messages For ASP.NET category:
How To Use C# Enumeration Values In JavaScript
I have got an enumeration in C# ie something like Category.cs. In a dropdownlist we are binding values. So if the user selects some specific value in dropdown it will hide one div. So i want to get the enumeration value in javascript ie want to compare the enumeration value with one selected value in javascript.

Posted: 2 days ago

View 2 Replies!   View Related
Set An Asp:listitem To An Enumeration Value Declaratively?
I have an asp:RadioButtonList and want to declaratively bind the value to an enumeration. I tried using this type syntax:

value = <%# ((int)MyEnum.Value).ToString() %>"

I get an error list item does not support databinding.

Posted: Jun 11 10 at 17:57

View 2 Replies!   View Related
C# - Form Control ID Is Null On Enumeration?
I have a simple ASP.Net page, and I am enumerating through the controls doing things to the controls via reflection (localising the page - but that is whole other can of managerial dictat type worms). So...I have a test page thus:

<%@ Page Title="" Language="C#" MasterPageFile="~/Master Pages/Root.master" AutoEventWireup="true" CodeFile="refelectiontest.aspx.cs" Inherits="refelectiontest" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Button ID="Button1" runat="server" Text="Button" />

[Code]....

Now, if I just run this, it barfs with an object null exception. And if I step through the code, putting a breakpoint on the control.ID line, then indeed the ID is null. However, if I then expand the control object, the ID fills itself out and all is well.

It looks like the ID is only getting completed at the last moment - how can I ensure that I can get the ID without getting null? The same thing happens if I don't use the master page.

Posted: Apr 2 at 11:36

View 2 Replies!   View Related
Collection Was Modified - Enumeration Operation May Not Execute?
I have the following code to delete selected items from repeater. I get the following error when the code is excecuted:

"System.InvalidOperationException: Collection was modified; enumeration operation may not execute."

and here is my code:

[Code]....

Posted: Sep 14, 2009 11:08 PM

View 1 Replies!   View Related
C# - Error - Collection Was Modified / Enumeration Operation May Not Execute
I have GridView and I need HTML ENCODE all values being update using Event handler _RowUpdating.

At the moment I use this script BUT I receive an error:

Collection was modified; enumeration operation may not execute.

[code]....

Posted: Jan 4 at 7:22

View 2 Replies!   View Related
Forms Data Controls :: How To Bind A Dindable Control To An Enumeration
I have this unemeration and I want it to be the list in a drop down lists:

Public
Enum ImmigrationType
As
Integer
TempWorkPermit = 3
TempWorkPermitSpecialOccupations = 7
Entrepreneur = 15
EntrepreneurSpecial = 31
Farmer = 63
Familly = 127
FamillySpecial = 255
SemiUnskilledWork = 511
SkilledWork = 1023
SemiUnskilledWorkSpecialOccupations = 2047
SkilledWorkSpecialOccupations = 4095
Nominee = 9191
End
Enum

cant seem to find how to do this...

Posted: Nov 11, 2009 07:41 PM

View 4 Replies!   View Related
.net - Dataset In Cache: Collection Was Modified; Enumeration Operation Might Not Execute
I'm storing a dataset in an ASP.Net WebApplication-Cache. Every user in this intranet-app uses the same instance. On insert/update/delete-actions the database will be updated and the dataset is modified accordingly.

But rarely I get an exception that indicates that I've missed something. I assume that it must have something to do with thread safety.

Collection was modified; enumeration operation might not execute

In lines where i access a DataTable in the Dataset, for example:

Dim view As New DataView(dsERP.ERP_Charge, filter, sort, _
Data.DataViewRowState.CurrentRows)

It was apparently changed by another thread while the view enumerates the datatable.

What is the best way to make this thread safe?

Edit: as you've mentioned i need to lock the objects on add/edit/delete operations. MSDN* says that a DataSet is thread-safe for multiple users. What does this mean, are the DataTables in the Dataset also thread-safe? And how to lock a single datatable on write-operations and not the whole dataset?

*ADO.NET - Multithreaded Programming ADO.NET is optimized for performance, throughput, and scalability. As a result, the ADO.NET objects do not lock resources and must only be used on a single thread. The one exception is the DataSet, which is thread-safe for multiple readers. However, you need lock the DataSet during writes.

This is the property that returns the dataset:

Public ReadOnly Property dsERP() As ERPModel.dsERP
Get
If Cache("DS_ERP") Is Nothing Then
Cache("DS_ERP") = New ERPModel.dsERP
FillDataSet()
End If
Return DirectCast(Cache("DS_ERP"), ERPModel.dsERP)
End Get
End Property

i've modified the insert/update and delete operations in the following way(dsRma is a dataset):

Dim success As Boolean
SyncLock dsRMA.RMA
success = insert()
End SyncLock

First, does it work now if another thread tries to enumerate the RMA-Table? Second, is it sufficient to lock the datarow that gets updated instead of locking the whole datatable(see below)?

Dim thisRMA As ERPModel.dsRMA.RMARow = dsRMA.RMA.FindByIdRMA(Me.IdRma)
Dim success As Boolean
SyncLock thisRMA
success = update(thisRMA)
End SyncLock

Posted: Mar 25 at 12:27

View 1 Replies!   View Related
C# - Remove An Item From A Collection (MembershipUserCollection) - Enumeration Operation May Not Execute
I use asp.net 4, ef 4 in c#.I use System.Web.Security to manage users in my web application.

I have a collection of users in MembershipUserCollection and I need remove some users during a foreach on that collector.

I suppose it is impossible to remove an item from the collector when you are looping.

MembershipUserCollection users = Membership.GetAllUsers();
foreach (MembershipUser x in users)
{
if (!Roles.IsUserInRole(x.UserName, "CMS-AUTHOR"))
{
users.Remove(x.UserName);
}
}

Error: Collection was modified; enumeration operation may not execute.

Posted: Mar 8 at 15:47

View 6 Replies!   View Related
Error Message: Collection Was Modified; Enumeration Operation May Not Execute?

I have 2 Lists and have 2 foreachs. I wil check if there are eqauals articleNumbers in the 2 Lists. If he found one he must remove it from the List allRequestedItems. But I get the error:

Collection was modified; enumeration operation may not execute.

List <ConfigurationItem> allRequestedItems = GetItems(null, null, null, 8, null, null);
foreach (ConfigurationItem requestedItem in allRequestedItems)[code]...

Posted: Nov 06, 2009 07:26 AM

View 3 Replies!   View Related
Report Viewer With A Date Range Error / The SqlDbType Enumeration Value, 31, Is Invalid
I have a aspx page withreport viewer that prompts the user for a begin date (dtBeginDate )and a end date ( dtEndDate ). I have a third party date picker control that they use to select the dates (data type on SqlServer 2008 is Date). Once that occurs and the user clicks submit and runs my code behind (below). When I run this on local host the report works fine. When I publish this to our intranet and run the report I get the following error: The SqlDbType enumeration value, 31, is invalid.

[code]....

Posted: Oct 07, 2009 12:26 AM

View 1 Replies!   View Related
Web Forms :: DropDownList.DataBind - Collection Was Modified / Enumeration Operation May Not Execute?
I created this generic method to Bind Controls on my ascx:

[Code]....

I cannot use a for cycle, it must be generic to load several DropDownList or CheckBoxLists on my web user control.

Posted: Oct 29, 2010 10:16 AM

View 1 Replies!   View Related
Web Forms :: Dropdownlist Error - Collection Was Modified; Enumeration Operation May Not Execute
I am trying to run following, it is giving me error "Collection was modified; enumeration operation may not execute" how can I resolve

[Code]....

Posted: May 13, 2010 06:13 PM

View 10 Replies!   View Related
MVC :: ClientValidationEnabled Bug In MVC3?
When I have this in my web.config then everything works as expected:

<appSettings><addkey="ClientValidationEnabled"value="true"/><addkey="UnobtrusiveJavaScriptEnabled"value="true"/></appSettings>
The client validation runs.

However if I turn off the second one, unobtrusive, I would still expect that client validation would work. However it seems to me that it still posts back fully to the server instead of client side validation only. Is this a bug in MVC3?

Posted: Feb 09, 2011 09:44 PM

View 2 Replies!   View Related
Possible Update To MVC3 From MVC2 Web App
I tried upgrading the solution to MVC3 in VS2010 by using an upgrader tool I don't know what it does exactly but it didn't work. My "System.Web.Mvc" is not being recognized in my project. Is there anything specific I should be doing with my web.config? I don't quite understand the underlying details about all the places I should be referencing dll's or what "binding" even means and when I should use it inside the web.config So I have to ask, what is the best method for upgrading to MVC3 and what have you done that works?

Posted: Feb 8 at 22:32

View 1 Replies!   View Related
C# - Learning Ajax With MVC3?
I am using MVC3 with LinQ and Entity framework and I want to start applying ajax. Where is the best place to start?

Posted: Mar 29 at 8:22

View 3 Replies!   View Related
How To Use Attributes As Mappath In Mvc3
In mvc1, we can write an attribute as '[NewPath("mainpage", Controller = "BrowsePdts", Action = "Index")]' before Action for 'mappaththen we can do sth. as'mappath' in webformI just want a navigate in the top of page , as 'book
>>magazine >> fashion'but what the attribute change to in mvc3?

Posted: Mar 19, 2011 07:26 AM

View 3 Replies!   View Related
MVC :: MVC3 Validations Not Firing?
When the submit button is pressed, the form just posts. No validations occur. What am I missing???

Web Config:
<appSettings>
<add key="ClientValidationEnabled" value="true" /> [code]...

Posted: Mar 21, 2011 04:52 PM

View 2 Replies!   View Related
Can Add Mvc3 Unobtrusive Validation For Min/max Validators
I'm trying to implement client validation for my custom type, however i'm not sure how to do it for min/max validators.

[MultilanguagePropertyRequired(ErrorMessageResourceName = "fld_Description_val_Required", ErrorMessageResourceType = typeof(Resources.Service.Controllers.Firm))]
[MultilanguagePropertyStringLength(1000, MinimumLength = 150, ErrorMessageResourceName = "fld_Description_val_MinLength_lbl", ErrorMessageResourceType = typeof(Resources.Service.Controllers.Firm))]
[Display(Name = "fld_Description_lbl", ResourceType = typeof(Resources.Service.Controllers.Firm))]
public MultilanguageProperty<string> Description
[code]...

Posted: Mar 25 at 12:16

View 2 Replies!   View Related
How To Create Submit Buttons In MVC3
with creating a submit button?What I need to do is1. Take a parameter from a text field2. Send that parameter to a function to get data when the user clicks submit3. return that data back to the calling page.


Posted: Mar 25, 2011 02:17 PM

View 12 Replies!   View Related
Clear Validation Summary Mvc3?
I am using mvc 3 unobtrusive concept for validation . It is working fine at client/server side.The problem is that it wont clear until I hit the server again.

Is there any extra code i have to write to clear validation summary ?

Posted: Jan 6 at 4:01

View 2 Replies!   View Related
How To Unit Test ValueProviderFactories In MVC3
We wanted to upgrade our projects from ASP.NET MVC 2 to 3. Most of our tests succeeded, but there are some that fail on ValueProviderFactories.Factories.GetValueProvider(context).

Here is a simple test class that ilustrates the problem.

[TestFixture]
public class FailingTest
{
[Test]
public void Test()
{
var type = typeof(string);
// any controller
AuthenticationController c = new AuthenticationController();
var httpContext = new Mock<HttpContextBase>();
var context = c.ControllerContext = new ControllerContext(httpContext.Object, new RouteData(), c);

[Code]...

Posted: Jan 5 at 11:55

View 2 Replies!   View Related
HttpHandler Not Working In MVC3 Web Application
I've recently taken an existing ASP.NET 3.5 web forms application that was upgraded to .NET 4 last year (and has been running fine) and configured it to also run ASP.NET MVC3 following Scott Hanselman's blog post: Integrating ASP.NET MVC 3 into existing upgraded ASP.NET 4 Web Forms applications. It works well and I've successfully begun to introduce views based on Razor and the existing aspx pages continue to work.

The one thing that has stopped working, however, is a custom HttpHandler (our load balancer hits a specific address to ensure the application is available - the handler is for that address). The web.config has always declared the handler in the system.web section like this:

<httpHandlers>
<add verb="*" path="system/heartbeat.aspx"
type="My.Monitor.HttpHandlers.LoadBalancerHandler, My.Monitor"/>
</httpHandlers>

Now we're testing post-MVC3 and I'm getting an exception that reads:

The controller for path '/system/heartbeat.aspx' was not found or does not implement IController. I have defined a RegisterRoutes method in my Global.asax and that method is called from the Application_Start. Within RegisterRoutes I've got the IgnoreRoute declarations from Hanselman's blog:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");

which I thought was to prevent the Routing system from taking anything with an extension of .aspx. I can reproduce the issue in VS2010 as I debug, and the deployment environment is running IIS 6. What can I do to prevent the Routing system from trying to handle that address so the custom handler can do it's thing?

Posted: Apr 1 at 17:03

View 1 Replies!   View Related
MVC3 Deleting A Record Using A Sub-form
I am trying to delete a record being displayed in a table on my ManageUser view using a sub-form, thus

<table cellpadding="2" cellspacing="0" border="1" summary="User Grid" style="text-align: left">
<tr style="background-color: #ABC3CB;">
<th align="center">User Name</th>
<th align="center">Approved</th>.....

but instead, it is returning directly to the Admin/ManagerUser view, thus displaying my original set of records again.

Posted: Feb 1 at 11:21

View 1 Replies!   View Related
MVC3 Deriving From DataAnnotations Attributes?
I have this working perfectly

[Required(ErrorMessageResourceName = "ValidationError_Required", ErrorMessageResourceType = typeof(Resources.Resources))]
public string Title { get; set; }
public class LRequiredAttribute : System.ComponentModel.DataAnnotations.RequiredAttribute
[code]...

Posted: Jan 28, 2011 08:22 PM

View 2 Replies!   View Related
C# - Create Dynamic Controls Using MVC3?
I need to create dynamic fields (textbox,combo) based on the entries in an XML file

I will read the ATTRIBUTES XML tag and must create the type of control and add validations to it. Can someone say how to use MVC3 to create dynamic controls, becos i cannot have different class for models as the XML file will change for each screen and i will have one screen which will generate this page for me...

Posted: Mar 28 at 6:11

View 1 Replies!   View Related
.net - MVC3 AllowHtml For Custom Types
I have a custom type in my model like so:

[StringLength(1000, MinimumLength = 150, ErrorMessageResourceName = "fld_Description_val_MinLength_lbl", ErrorMessageResourceType = typeof(Resources.Service.Controllers.Firm))]
[AllowHtml]
[Display(Name = "fld_Description_lbl", ResourceType = typeof(Resources.Service.Controllers.Firm))]
[code]...

Posted: Mar 28 at 6:52

View 1 Replies!   View Related
MVC :: Vs2010 Not Showing Mvc3 Option
I just setup new vs2010 ultimate environment.And now trying to learn mvc3 pattern usinghttp://www.asp.net/mvc/tutorials/getting-started-with-mvc3-part1-cs.But the IDE has no mvc3 option there.i have already installed mvc3 packege.

Posted: Mar 13, 2011 04:14 AM

View 2 Replies!   View Related
MVC3 Make Possible To Use IOC With Action Filters?
Will MVC3 make possible to use IOC with Action Filters? Is this on the roadmap?

Posted: Aug 22, 2010 05:42 PM

View 1 Replies!   View Related
C# - Take A Textbox And Print The Contents In A Url (MVC3)?
I have a view with a textbox and a button. I want to take the textbox and take the contents of what a user types in and put it as a "Get" variable in the URL. Does anyone have a simple example of this? I want it to print into a url like this: /Profiles/Search?searchstring=hello

I am using razor built in mvc3 view

Posted: Mar 19 at 6:40

View 1 Replies!   View Related
MVC ::get Details About Mvc3 Life Cycle?
I am still new to mvc.I want to get details about mvc3 life cycle,

Posted: Mar 08, 2011 01:53 AM

View 2 Replies!   View Related
Building An Enterprise Application With .NET MVC3?
Im in the process of building an Enterprise Application, I want to have the DAL & BLL in separate projects, one each.With a structure like this, what should i do with the Models folder inMVC'SDefault Project?

Posted: Nov 30, 2010 03:12 PM

View 3 Replies!   View Related
CustomErrors Mode = "off" Error - Invalid Data Type "NM Token - Enumeration Constraint Failed"
I 'm using visual studio 2007 and I have come up with an error in my web config that I have never come up with before. I have set customError mode "off" in my web config and I'm getting an error code of The 'mode' attribute is invalid ' The value 'off' is invalid according to it's data type 'NM Token' - the enumeration constraint failed what an 'NM token' is and what I can do to fix this problem? My page works perfectly when I'm working on it locally, but when I move it to the web server I get an error and it tells me to set the custom mode errors in the web config to 'off' This is the error I'm getting:

Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".

Posted: May 25th, 2010, 08:30 AM

View 2 Replies!   View Related
Mvc3 Html.renderpartial On Master Page?
im getting the following exception for use into a master page the helper html.renderpartial(). This works on mvc views that uses this master page, but im trying to execute an old aspx webform page that uses the same masterpage. And here comes following exception:A ViewMasterPage can be used only with content pages that derive from ViewPage or ViewPage.This is the code of my master page:

<body>
<%Html.RenderPartial("PartialView"); %>
<div style="background-color:Aqua;">
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
</div>
</body>

I would like to render some partialviews on my master page. Is it possible?

Posted: Nov 23 10 at 8:55

View 1 Replies!   View Related
C# - MVC3 System.ComponentModel.DataAnnotations And Association?
This part of code works fine

[Association(Storage = "profile", ThisKey = "UserId", OtherKey = "UserId")]
public Profile User {
get { return this.profile.Entity; }
set { this.profile.Entity = value; }
}

but if i add in this class System.ComponentModel.DataAnnotations then, Association could not be found.

Posted: Feb 16 at 10:28

View 2 Replies!   View Related
How To Generate Absolute Urls With Https In MVC3
I am using MVC3 and am trying to serve content from https, the problem is that when I call Url.Content the files are still served from http using a relative url. I thought this problem was addressed in MVC3 but i can't seem to find any solution. Does anybody know if this issue is inherently solved in MVC3 and how to accomplish it or do I need to create my own helper methods to generate absolute Urls based on protocol?

Posted: Apr 4 at 13:27

View 2 Replies!   View Related
C# - Viewengine Not Looking Into Areas For Views In Mvc3 Upgrade?
i'm upgrading my asp.net mvc app to the MVC 3 from mvc 2. I had everything set up so that there were no areas, but now i have to move the old application into its own area so i can start a new one. The new area is working great, but for some reason, when i try to go into the area where the old app was, it looks for the views to be in the views folder in the root of the app, instead of in the views folder in the area.

Posted: Mar 10 at 17:30

View 2 Replies!   View Related
MVC :: MVC3 - Passing Data To The Layout Page?
What is the best way to pass data to the layout page? Each one of my pages has a different model, but I need to pass consistant data to the layout pageso I can show the current app they are on and the array of menu options that get passed into a method that builds the menu.

Posted: Nov 18, 2010 01:36 PM

View 2 Replies!   View Related
MVC3 - All Routing Works Locally But Not Remotely?
I have a new MVC3 project with one Controller called PublicController.cs which contains 4 identical methods for testing out how routing works. The only difference between them is their name, and that they each point to a different view ...

public class PublicController : Controller
{
//
// GET: /Public/
public ActionResult Index()[code]....

My web-server is shared hosting with netcetera, using a sub-domain for this deployment (previously had problems with MVC in virtual directories, but have full blown MVC2 apps running in sub-domains no problem). I've deployed by using the "Publish to file system" option, then copying over the files aswell as just copying the entire source project over. Both give identical results.

Posted: Feb 16 at 3:56

View 1 Replies!   View Related
Design Pattern For Adding A Web Service In MVC3
Firstly - I'm not asking this question How to include a web service in MVC3? I know where the button is :-)

I'm trying to find an example of best practices of how to use the new DI / Common Service Locator framework in order to make web service calls (and code dependent on web service calls) testable. I've no experience of using NInject or the like - is that the way to go?

Posted: Mar 4 at 16:59

View 2 Replies!   View Related
Copyright 2005-08 www.BigResource.com, All rights reserved