asp.net-mvc

MVC Controller parameter for a form element with a dot in it?

If you're using the Html.TextBoxFor() type methods, you may well end up with Form controls that have dots in their names, like this: <input type="text" name="Contact.FirstName" id="Contact_FirstName" /> If you want MVC to map those named fields to parameters in your controller (as opposed to an object parameter or whatever), you have t...

Problem with AJAX, JavaScript, ASP.Net MVC

Hi, everyone! I'm writing Asp.Net MVC 2 site. I have TimeController and TimeView, CountDownHelper for render time on TimeView page. Also I have JavaScript that updates current time, that is used in CountDownHelper. I need to call AJAX from this JavaScript to get current Time on server. How I can to do it? Please help me! I must i...

Question about custom routing in ASP.NET MVC

Hi all, I have to admit in advance that I'm quite new to MVC, I've been going through the resources at www.asp.net/mvc, but I was wondering if you guys could help me with something. I have been asked to create a ASP.NET version of an existing PHP website, this website has a huge number of existing links to it in a particular format, wh...

ASP.net MVC create table record with foreign key

I have multiple tables that are all linked back to a central table with foreign keys. I want to be able to create a new record in table 2, but I'm having trouble because I don't know how to create a new instance of table 2's record while referencing the ID of the record it will be tied to. EXAMPLE: Database: Collection Table: Collect...

.net MVC 2 default Route suddenly stopped working

Hello, today the default route for my site stopped working, but the strange thing is that the global.ascx has not changed at all. when i enter the URL mysite.com/ i get this 404 error The resource cannot be found. Requested URL: /Views/Start/Index.aspx i have a bog standard default MVC route routes.MapRoute( ...

Choose Connection String from view in ASP.NET MVC

Hi everyone I have a LogOn view look like this <%= Html.TextBox("username", "", new { @style = "width:149px;border:1px solid #CCC" })%> <%= Html.Password("password","",new { @style = "width:149px;border:1px solid #CCC" }) %> <%= Html.DropDownList("SrvId", (SelectList)ViewData["ServerID"], new { @style = "width:149px;border:1px solid #CC...

Stringlength constraint for route?

Hello I was planning on having 2char language in url, like something.com/EN, /ES, /US. Is that possible to add a 2char constraint for a route? /M ...

Issues with aspnetForm in hybrid asp.net webforms/mvc app

I am building a hybrid MVC/Webforms application where my MVC views are using an asp.net webforms 2 MasterPage. Everything has been working perfectly until I decided to put a form in my MVC view. Since ASP.NET Webforms wraps the entire page in a form element and you can't have a form within a form, I'm a little bit stuck. There are a lo...

How can I remove magic strings from custom model binders?

I've written a couple of custom model binders now, and have realised that I've fallen into the trap of relying on magic strings, e.g.: if (bindingContext.ValueProvider.ContainsPrefix("PaymentKey")) { paymentKey = bindingContext.ValueProvider.GetValue("PaymentKey").AttemptedValue; } I'd like to be able to use an exp...

ASP.Net MVC - Images taking a long time to load

I have tested my pages in Firefox & IE and looking at Firebug in Firefox for some reason some images are taking a long time to load. They are not very big in comparison to the ones which are loading quicker. Attached is a screenshot of Firebug. I especially notice it in IE with the progress bar at the bottom of the page, it just sits ...

How UpdateModel method works in asp.net mvc 2

Hi, I want to know the working of UpdateModel() method. I just know about it is for update the current model data. but how it works exactly ? Because while I am using the UpdateModel() in edit controller method, there is functionality of file uploads. I am keeping the path of uploaded file in my db. but after executes the UpdateModel met...

Calling a method from a view

Hi, I have an Index view. On this view is a link, and it is created like this: <%= Html.ActionLink("Clear All", "ClearAll", "CachedCollections") %> I don't want to have a view for ClearAll, I just want it to go in the method, clear what it needs to clear and then post back to the Index view. How would I do this? Do I need to call ...

Asp.net generic principal problem

Using this code for authentification: HttpContext.Current.User=new GenericPrincipal (new GenericIdentity(user.UserName), roles); FormsAuthentication.SetAuthCookie(user.UserName,false); Problem is - on next request, HttpContext.Current.User.IsAuthenticated is true, but HttpContext.Current.User.IsInRole("admin") is false. There are a...

HtmlEncode error on a generated view.

I've just set up a small R&D MVC2 project, and I've basically used only the wizards to add a partial view for my Customer object, which as a Linq to SQL entity. When I try and visit the Create view for Customer, I get the following error on the RenderPartial method in the Create view: Compiler Error Message: CS1502: The best overloaded...

WebForms vs MVC vs CMS - What platform to go for an e-commerce application?

I am planning to create an ecommerce application which would host a lot of products (more than 100) and expectedly would have good number of user hits/transactions on a daily basis. My major requirements from both functional and technical point of view are: It should be easily extensible/modifiable/maintainable. Usability would be the ...

should I use a static DbUtil class for web, is it dangerous ?

is it ok to use something like this in the web: (my application is on asp.net mvc) public static class DbUtil { public static int Insert(object o, string cs) { using (var conn = new SqlConnection(cs)) using (var cmd = conn.CreateCommand()) { ... conn.Open...

How to catch error in an ASP.NET MVC and display a gracious error message to the user?

I'm writing a very small application for my organization. As nobody seems to know what he wants, I've decide that I'll deploy a demo on our local server so people can get ideas on how to conceive the big thing. Now here's the problem: While developing on my laptop, when the application crashes, I get a yellow screen giving feedback on ...

Dynamic routing problem when invoking site from remote host.

Hell, I have error handling for my mvc app configured in the simplified way below (globals.asax): protected void Application_Error(object sender, EventArgs e) { Exception exception = Server.GetLastError(); Response.Clear(); RouteData routeData = new RouteData(); routeData.Values.Add(...

Should I write from Controller, Code Behind, or Helper in MVC?

I've seen all the questions and answers around not having code-behind for a view, however I have a case where I need complex logic to generate the presentation (view) layer. I have to output a PDF file based on data obtained from db. Where is the best place to generate this PDF and write to the response stream? Doing response.write fr...

Select multiple tables using Linq to SQL

Hi, I'm trying to bind columns from two different tables in to gridview using Linq To Sql Here's the bind: var q = (from o in mail.tblmails join c in mail.tblstaffs on o.staffId equals c.id select new { o, c }); return View(q); and here is where I'm calling the bind in my View. .Columns(columns => { colu...