asp.net-mvc-2

ASP.NET MVC and LINQ to SQL: linking table, checkboxes

I am very new to MVC and from what I learned, I can have a form (a View) linked to a Model. Now I have a View for adding a new Client, so the View inherits from Client. I have something like this for each field <%= Html.LabelFor(model => model.FirstName) %> <%= Html.TextBoxFor(model => model.FirstName)%> <%= Html.ValidationMessag...

ASP .NET MVC2 problem in calling jquery.get()

I am working on a ASP .NET MVC2 project where i have to load data using $.get() but it doesn't works. Although if i call same method with $.post() even giving [AcceptVerbs(HttpVerbs.Post)] above of my controller method or not it works. So i just want to ask Does Microsft has put a restriction inn calling $.get() with ASP .NET MVC2. If ye...

Show breadcrumbs when Passing GUID

Hi, I'm working with ASP MVC 2 RC2 and using the standard sitemap provider. I'd like to show breadcrumbs on a page which passes a guid in the url e.g. /validate/GUID but i'd like the system to ignore the GUID and just show the (Home > Validated) for the page, as I don't want to dynamically re-create the sitemap each time I create a n...

ASP.NET MVC 2 - Membership Provider - ValidateUser() - return login error message

How do I return a string message from the ValidateUser method in my custom membership provider? I need this because I want to perform several checks (user is approved, user is blocked etc.) and give the user a good description, if the login process fails. One option would be to throw an exception, but someone said that this is not a pro...

How Should Subsonic Migrations Be Run For ASP.NET MVC 2?

I'm not having any luck finding where in my code I should run migrations when I start up my application. Obviously this should only happen once, when the app starts. In Global.asax.cs I tried: protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RegisterRoutes(RouteTable.Routes); var repository = new...

Returning an EditorTemplate as a PartialView in an Action Result - ASP.Net MVC 2

I have a model similar to this: public class myModel { public ClassA ObjectA {get; set;} public ClassB ObjectB {get; set;} } In my main view, I have tags similar to this: <div id="section1"> <%=Html.EditorFor(m => m.ObjectA)%> </div> <div id="section2"> <%=Html.EditorFor(m => m.ObjectB)%> </div> ClassA and ClassB b...

ASP.NET MVC: Render checkbox list from MultiSelectList

How do you associate a MultiSelectList with a list of checkboxes? eg. I pass something like this to the model model.Groups = new MultiSelectList(k.Groups, "Id", "Name", selectedGroups) How should I render it? This doesn't work <% foreach (var item in Model.Groups.Items) { %> <input type="checkbox" name="groups" value="<%=item.Va...

ASP.Net MVC: Can an msi file be returned via a FileContentResult without breaking the install package?

I'm using this code to return a FileContentResult with an msi file for the user to download in my ASP.Net MVC controller: using (StreamReader reader = new StreamReader(@"c:\WixTest.msi")) { Byte[] bytes = Encoding.ASCII.GetBytes(reader.ReadToEnd()); return File(bytes, "text/plain", "download.msi"); } I can download the file, ...

MvcHtmlString MVC 2 Conversion Error

I converted my project from MVC 1 to MVC 2 and Visual Studio 2008 gives me the following error: Error 1 'System.Web.Mvc.MvcHtmlString' does not contain a definition for 'Substring' and no extension method 'Substring' accepting a first argument of type 'System.Web.Mvc.MvcHtmlString' could be found (are you missing a using directive o...

Distinguishing controller actions using authorization filters

I would like to have 4 actions with the same name (controller methods may have a different name, but their ActionName() attribute is the same for all 4 of them: [ActionName("Same-name")] public ActionResult AnonAction() { ... } [HttpPost] [ActionName("Same-name")] public ActionResult AnonAction(ModelData data) { ... } [Authorize] [Act...

maxlength attribute of a text box from the DataAnnotations StringLength in MVC2

I am working on an MVC2 application and want to set the maxlength attributes of the text inputs. I have already defined the stringlength attribute on the Model object using data annotations and it is validating the length of entered strings correctly. I do not want to repeat the same setting in my views by setting the max length attr...

Asp.Net MVC 2 DefaultModelBinder error using abstract classes

I have a simple Poco-Model using abstract classes, and it seems not to work with the Default ModelBinder of Asp.net MVC 2. One Item has several Objects in a collection, all using the same abstract base class. Model: public partial class Item { public virtual ICollection<Core.Object> Objects { get ...

Scripting ASP.NET MVC Views Stored In The Database [Haacked.com]

Following Philip Haack's article Scripting ASP.NET MVC Views Stored In The Database here, does anyone have a working example of building a view from a database? Since Phil's server crashed, the download has been broken and he hasn't, as yet, fixed it. So, does anyone have that download or do they have a working example of doing the same...

Can i have One form tag inside Another in ASP.net MVC RC2

Hi all, I am currently Developing application in MVC2 I have want to used mutiple form tags in My application In My View I have Created a table which has Delete option which i am doing through Post for Individual Delete so i have Create form tag for each button. i also want user to give option to delete mutiple records so i am pro...

How to display and update data in MVC2

Table Product Product Id Product Name Table ProductSupplier ProductSupplierId ProductId SupplierId Table Supplier SupplierId SupplierName I have the above 3 tables in my database, ProductSupplier is the lookup table. Each Product can have many suppliers. I am using Entity Framework. Using Web Forms it was fairly easy to display a Pro...

ASP.NET MVC 2: How do I make the Ajax.Form to fire the Client Side Validation with Data Annotation?

Here is the code I have so far: <% Html.EnableClientValidation(); %> <% using (Ajax.BeginForm("Address", "Accounts", FormMethod.Post, new AjaxOptions(){}, new { id="dialog-form"} )){ %> <div> <label for="address">Address Name:</label> </div> <div> <%= Html.TextBoxFor(m => m.Name)%> <div> ...

Is MVC Contrib Grid part of Asp.Net MVC 2.0?

Is it part of Asp.Net MVC 2.0. If not then does Asp.Net MVC 2.0 ship with in built GridView support? ...

Best way of implementing DropDownList in ASP.NET MVC 2?

I am trying to understand the best way of implementing a DropDownList in ASP.NET MVC 2 using the DropDownListFor helper. This is a multi-part question. First, what is the best way to pass the list data to the view? Pass the list in your model with a SelectList property that contains the data Pass the list in via ViewData How do I g...

Can ASP.NET MVC html helpers render an element without an ID attribute?

Assume I want to generate an element similar to this in ASP.NET MVC 2: <%= Html.TextBoxFor(p => p.FooBar)%> Is there an overload or way I can get ASP.NET MVC 2 to only generate a name attribute and not an ID attribute? I can have it generate a blank id with <%= Html.TextBoxFor(p => p.FooBar, new { id = "" })%>, but I would like to ...

Model binding postback data to a controller action parameter of type List<T>

I have a strong type view of type List<List<MyViewModelClass>> The outer list will always have two lists of List<MyViewModelClass>. For each of the two outer lists I want to display a group of checkboxes. Each set can have an arbitrary number of choices. My view model class looks similar to this: public class MyViewModelClass { ...