asp.net-mvc

ASP.NET MVC helper extensions & separation of concerns

When implementing a helper extension for a similar navigation widget to the one described in this article I notice that my HTML is now tied up in C# code, so if I want to re-skin the site with a new menu control that needs slightly different markup (e.g <ul class="foo">...</ul> or distinct class names for nested <li> tags) I now have to ...

How to set a Foreign Key relationship manually in LINQ To SQL

I've been working through the book Pro ASP.NET MVC 2 Framework by Steven Sanderson. So far it's been phenominal... just when i think I know a decent amount I find a book that shows me just how little I know. One of the things I know little about is how to use LINQtoSQL. In Steven's book, chapters 4-6 create a very nice little shopping c...

Returning a file using asp.net mvc ?

I have a custom IHttpHandler which is used by thick clients to download files using a url such as http://url.ashx?id=123&amp;version=456 the code handler basically ends with context.Response.WriteFile(myLocalServerPath); Is it possible to replace this using the typical asp.net mvc controller pattern ? ...

File Upload in MVC on an embedded user control .ascx file

Following the example here: http://www.highoncoding.com/Articles/689_Uploading_and_Displaying_Files_Using_ASP_NET_MVC_Framework.aspx I have an .ascx file I'm using as an editor template, and I would like to use this method to upload files, my .ascx file looks like so <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<M...

MVC 2 asp.net VC2010: Where happens the "databinding"?

Understanding question: 1.) "X_IndexViewModel" class public class X_IndexViewModel { public List<SelectListItem> CheckBox_1 { get; set; } ... } 2.) XController.cs public ActionResult Index() { X_IndexViewModel viewModel = new X_IndexViewModel { CheckBox_1 = new List<SelectListItem>() { ne...

Lucene(.Net) geometric (lat/long) queries?

I'm writing an ASP.NET MVC site where I plan to use Lucene.Net for searching. Some of my site content has a location attribute, and I'm thinking of incorporating location into the searching functionality. Does functionality exist in Lucene where, if I were to define latitude and longitude fields for my documents, the user inputs some co...

Why is my MVC ViewModel member overridden by my ActionResult parameter?

Is this a bug or a feature? All code below has been simplified for the sake of brevity and easy replication and does not actually do anything useful other than highlight the behavior. I have a class that includes an int named ID: public class FooterLink { public int ID { get; set; } } In my controller, I have an Edit actionresul...

Why should I use GetOriginalEntityState() in my LINQ To SQL repository save method?

I'm looking at an example of a save method in a Products repository from Steven Sanderson's book, Pro ASP.NET MVC 2 Framework: public void SaveProduct(Product product) { // if new product, attach to DataContext: if (product.ProductID == 0) productsTable.InsertOnSubmit(product); else if (productsTable.GetOriginalEntit...

Validating an Email Address on jQuery postback best practice

This question title is likely to be worded poorly so feel free to adjust. In my MVC application I have a custom attribute which i use to decorate email fields which then either passes or fails the model. On one pge though I allow the use to submit a comment but I submit via ajax and so do not do a full postback and no model validation....

MVC Controller Not Binding Id Param On Post

I have a Model that has several properties. When I submit a form, I pass along the values for those properties (generated by the jQuery $.serialize() method) and they are automatically bound. This works without a problem. However, now I want to add an Id to the string, and I have to do it manually since it's not a form field. I've done s...

MVC Architecture

I know similar questions have been posted before, but I have specific requirements that make this as far as I can find unanswered. The project wants to have a typical 3-tier architecture, but they want the data layer to be abstracted by Entity Framework, the presentation layer to be MVC 2 and the application layer to be simple class lib...

How to Validate a Model in a jQuery Postback

If I have a model; Name [Required] FirstName [Required] LastName If I create the model in my jQuery postback thus; Name name = new Name{ FirstName = param1, LastName = param2 }; Is there a way I can validate it using the data annotations that decorate the fields? This is not happening in a postback event on the view, it's ...

solrnet and ASP.NET MVC

Hello, I noticed in the solrnet examples it is not possible to drill down into search results. That is, you are presented with a list of products but cannot see the details for those products. My question is as follows: The MVC controller that calls SOLR and populates the index page essentially contains the model for each detail view...

Html.ActionLink does not display anything

I have this simple snippet with an ActionLink that is supposed to display some text as a link, but it's not working. Here's the code snippet. <div id = "Div1"> <table id = "Table1"> <% while ((category = SomeNamespace.Helper.GetNextCategory(categoryIndex++)) != null) { %> <tr> ...

How to use a namespace within an MVC view?

This should be simple and I don't know why the compiler is complaining. I have a view and I want to shorten this call inside it: <div id = "catalog"> <table id = "catalogContainer"> <% while ((category = SomeNamespace.Helper. GetNextCategory(categoryIndex++)) != null) to not quali...

CSS not working

Sometimes the dang thing works and at other times it doesn't. I have many tables in my app and the CSS for all of them is working. There's nothing different for this one, except for it, the CSS isn't being applied, God knows why. Help. table.catalogContainer { border: none; padding: 50px; margin-left: 100px; margin-right...

What's the point of Html.DisplayTextFor()?

Is there a good reason to use the strongly typed html helper... <%: Html.DisplayTextFor(model => model.Email) %> As opposed to... <%: Model.Email %> ...

Add property decorator to partial class

I have a partial class in a dbml file. public partial class Comment string email Clearly I can't put a decorator on it because this is a generated file and you shouldn't make change in it yourself. So I created another partial class; public partial class Comment [IsEmailAddress] string email The above doesn't work but I need...

How can I Create, write and then return a file in C# without saving it to disk

I'm working on an ASP.NET MVC App that has buttons that have the server return an rdp file, which is created by my business layer. What I want is to be able to have the server create this rdp file, then serve it, without having it stored on disk. What would be the best way to go about this? Thanks. ...

How do you place a web services aside with your ASP.NET MVC web application

Hi all, I currently have a web application written by ASP.NET MVC. Now I want to add a web service so that some people can easily build application upon it. Shall I just create the asmx in the MVC Web project or create another project referencing to the Model project? And what's the pros and cons? Thanks in advance! ...