C# - MVC2 IModelBinder And Parsing A String To An Object?
Feb 2, 2010
I have an object called Time
public class Time{
public int Hour {get;set;}
public int Minute {get;set;}
public static Time Parse(string timeString){
//reads the ToString()'s previous output and returns a Time object
}.....
So what I want is for the automatic model binding on the Edit or Create action to set this Time instance up from a string (i.e. feed the Parse method with the string and return the result).
The reason I am doing this is that I will have a DropDownList with selectable times. The value of each option will be the parser readable string.
I'm looking for a way to parse excel into Asp.Net, the problem I'm experiencing same as in[ URL]
I've searched all web, but no1 seems to have an answer
here's the error
The Microsoft Jet database engine could not find the object 'Cities'. Make sure the object exists and that you spell its name and the path name correctly.
I'm writing a class to automatically extract information from an excel spreadsheet (using NPOI api) in C#, and then import this information into a database. I've got it all working fine except for one small issue.
One of the spreadsheets I'm working with, contains the date in the following format: 04/01/2011 04:43:28.
When I ran the web application, I got the following error message:
String was not recognised as a valid
So I debugged through the code after this, and it turns out that the date is being read in as:
40546.0151388889, so it is being formattted back to a number.
I am looking at ASP.NET MVC2 and trying to post a complex object using the new EditorFor syntax.I have a FraudDto object that has a FraudCategory child object and I want to set this object from the values that are posted from the form.Posting a simple object is not a problem but I am struggling with how to handle complex objects with child objects.I have the following parent FraudDto object whcih I am binding to on the form:
public class FraudDto { public FraudCategoryDto FraudCategory { get; set; }
First I incorrectly had my node defined in /shared/web.config instead of the web.config in the root of the WebUI project. I also had not correctly defined my connection string within web.config. I have pasted the proper web.config sections below:
I need to put a Flash Object in my website developed on MVC2 .NET, however the third party who made it just gave me an html with this code.HTML errors apart I don't know how to put it on ASP.NET.
But the complete text is not displayed when I add just a dot "." to "Hello World". I thought "<%:" takes care for this but it seams that this is not true... How to solve this? How to mask the dot? Changing "." with "%2E" doesnt work ;-(
In the original site, master page has code-behind to check a query string parameter value. Depending on this value, code-behind dynamically modify some CSS property to hide / display master page elements.
As MVC2 has no code-behind because we are supposed to perform everything in the controllers, how should I proceed in this case ?
I see this : [URL]
It partially answers my needs but the query string processing is common to all pages. How can I move this processing in a common code section ?
<%@ Import Namespace="System.Data.SqlClient" %> <script runat="server" > Dim connStr As String = ConfigurationManager.ConnectionStrings("cc").ConnectionString.ToString dim db As New Data.SqlClient.SqlConnection(connStr)
why this error
Object reference not set to an instance of an object.
on VWD 2005 this code works fine, but on 2008 it says I haven't created an instance of the object. I want to convert the object connString (a connection string) into a string.
'This acceses the virtual directory web.config file for connection strings 'We have to convert the object to a connection string Dim rootWebConfig As System.Configuration.Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/VirtualDirec") Dim connString As System.Configuration.ConnectionStringSettings connString = rootWebConfig.ConnectionStrings.ConnectionStrings("ConnectString1") Dim strConnString As String = connString.ToString().......
public class Package { public Package() { name = ""; type = new List<Dictionary<string, string>>(); } public string name { get; set; } public List<Dictionary<string, string>> type { get; set; } } [code]...
Prior to using a ViewModel, I could easily pass the "soon to be edited" object directly to the view without needing to fuss over setting individual properties etc as the View conveniently accepted the Employee type directly..
[HttpGet] public ActionResult EditEmployee(int? id) { EmployeeRepository ER = new EmployeeRepository(); Employee SomeEmployee = ER.GetEmployee(id.Value); if(SomeEmployee!=null) return View(SomeEmployee);
But now I'm using a ViewModel with DataAnnotations attributes applied over the top of various properties for validation purposes. Which creates a problem.. After fetching the "soon to be edited" object from the db, setting the ViewModel's values is suddenly a whole lot more complicated. I can't simply pass the retrieved object straight to the view, as the View now expects the VMEmployee type instead. I would like to be able to do something like:
[HttpGet] public ActionResult EditEmployee(int? id) { EmployeeRepository ER = new EmployeeRepository(); Employee SomeEmployee = ER.GetEmployee(id.Value); if(SomeEmployee!=null) return View(new VMEmployee(SomeEmployee));
All paths seem to lead to a huge constructor which manually sets the values of each individual property. But I never had to do that before when I wasn't using a ViewModel. Model binding was a blessing! My objects also have complex child objects, which my form is also collecting values for, so this would be a huge/verbose task against DRY principals. I don't even really want to use a ViewModel, but am forced to because I need two different DataAnnotations rule sets for different validation scenarios applied to the same object.
All I want to do is be able to have two different DataAnnotations rule sets for different scenarios. I.e. public-facing www site vs internal-facing admin site. DataAnnotations doesn't seem to be flexible enough to easily cater for this common need. I've tried AutoMapper, but it throws an error saying it can't map my object types, I suspect because Employee was auto-generated by LINQ to SQL. What is the most elegant way to achieve this while sticking to DRY principals?
How can I do this using XmlDocument?I want readability over performance, and I find XmlReader to be hard to read b/c you have to keep checking the node type.
I want to do is to get the record number in my database of the first record that matches my search. Its to skip to a random point in the database based on user input.
[Code]....
It returns the number of records that preceed the first one to match the string. I have tried to call this procedure from MVC and it always returns -1, so I have a fundamental problem there. I have also tried ot figure out how to just duplicate the code in MVC and I also cannot seem to get anywhere on that front.
Does anyone know a simple elegant solution to either embed this code diretly into MVC or to call my stored procedure from MVC and get the correct integer response back, instead of -1? I am engaged in relearning development after many years, so I am getting stuck on the basics.
can i add string builder object to a dictionary object? If yes code it. I mean i have a dictionary in which i have already added a few (string, objects), and i have a string Builder which has few variable already added now i want that instead of passing 2 different object in a method i want to pass only one object so can i add string builder object to same method as well