asp.net-mvc

mvc - show/hide stuff based on what view it is for a user control

Hi, Im using asp.net mvc. I have a create and edit form which are very similar so im using a user control for the form. and placing that in each view. the form is very slightly different on the edit form eg it has some extra text and a link. how can i show/hide that based on the view im in? ...

jquery sortable, get list order

Is there any to return what rank in a list something is in during a sort using jquery? Essentially, I want to do what thousands of others are doing (and I've searched thoroughly on stackoverflow) and have a database update from a sortable. Each item in the database has a "Position" property - initially set to 0. The ul is populated and ...

Entity Framework and LINQ Include()

Hi I am new to Entity Framework and LINQ and have run into a rather odd scenario. I have been using the following query to return account information: var account = ((from acct in _entities.Account join m in _entities.Item on acct.Id equals m.Account.Id where acct.Id == accountId && m.It...

BeginForm() generates default.aspx? when on the Index view of the Home Controller

On an MVC 1.0 site, Right out of the box, if I add an input type=submit button to a form created with Html.BeginForm i'll get an action of "/Default.aspx? This is not what I was expecting. This seems to be the case only with the sp-called default view. The upshot of all this, that there will be a /defaul.aspx? in the addressbar when t...

How to route MVC URL mistakes to a view of our choice?

If we use this standard route: routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = "" } // Parameter defaults ); and within Windows 2008 IIS7 with MVC 2 setup ...

ActionLink<> generic version not found

I am a bit fed up with these Html helpers. I did a lot of research on the net but can't finf anything.. Am I the only guy on earth that can't get the Html.ActionLink working... Here is what I am trying to get working : <%=Html.ActionLink<CatalogController>(x=>x.Index(parent.Name,child.Name),child.Name) %> I get the ActionLink metho...

DDD-friendly ASP.NET MVC Model Binder?

I'm considering the value of a custom model binder that can instatiate immutable value objects defined in my domain layer. Then I can just pass them through the stack and set them on the appropriate entity. Has anyone tried? Had any luck? Think its a silly idea? ...

Post/Redirect/Get Pattern in ASP.NET MVC

What is the best practice for implementing the Post/Redirect/Get pattern in ASP.NET MVC? In particular, what is the best way to do this when you want to redirect back to the initial action/controller? Here's how I am currently doing this: Display form to user. In the form, use <%= Html.Hidden("returnUrl") %> In the action, use ViewDa...

ASP.NET MVC1 - Not all Request fields being returned in Model... (NOOB question)

I'm working on my very first ASP.NET MVC project, and I'm seeing strange behavior when returning data from an Edit View to my controller action. Right now, I have 3 textboxes on the page, plus one hidden one for the PKey. All are being populated from the viewdata correctly, but when I submit the form, only 2 of the 3 fields show up in ...

Why doesnt my jquery execute?

Hello! Im trying to show and hide a div element with the jquery toggle method. I have a linkbutton that onclick calls the javascript on the page. When clicking the linkbutton the page does a postback even when I declared the javascript function to return false. Someone got an idea how to solve this? function toggleDiv(){ $('#app...

ASP.NET MVC Multiple Layout

I have a website that will contain 2 type of layout. With no columns With 2 columns Header, footer and lots of other parts are the same for both, but inside the main content, there 2 separate layouts and I'd like to choose between 2 site masters. How would I go about accomplishing this? I was thinking about making a main site maste...

ASP.Net MVC Ajax RenderPartial not rendering correctly

I have an AJAX form which returns a partial view, but instead of the target div getting updated, when I submit, only the partial view is shown. As far as I can tell, I have everything set up the way it's supposed to be, what's going wrong? <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ApplianceSurvey.Models.Ite...

Asp.net mvc model validation

What are the best practices? ...

mvc return Json() vs. JSON based Web Service

I want to expose a service on my site that any users can call and get a JSON response. In the end, I want the users to be using this service as much as possible. My site is created using the asp.net MVC framework and i was wondering whats the best way to do this... I think most would say it's obvious to use a web service (*.asmx) that ...

Someone is eating my <?xml version="1.0"?> returning an Excel XML in Asp.net MVC

I'm playing with VB XML literals for returning and Excel XML file. the problem is that the first line containing <?xml version="1.0"?> does not make to the download. Here is the code: Public Class ReservasController Function Test() Response.Clear() Response.AddHeader("Content-Disposition", "attachment; filename=test.xml") ...

Help with asp.net mvc authorization

Say you want to display a menu that has many elements... Some elements are exclusive to users with "administrator" role. I know how to restrict controllers methods using [Authorize(Roles = "Administrators")] but I want to figure out a way to display a specific html thing depending on the user roles example <ul> <li>Menu Item 1</li...

Get encompassing class, then access a property of it inside custom attribute

I'm using ASP.NET MVC and implementing custom validation via custom attributes/data annotations on my models. Is it possible to access a property on an object's parent class inside my custom attribute? public class MyModel { [MyCustomValidator] public string var1 {get; set;} public string var2 {get; set;} } Note: Using as...

Data Annotation/Validation and dynamic values

If some of my models have dynamic validation conditions (i.e. the string length can be minimum of 8 or 12 depending on a database value or some other dynamic value) is it impossible to use data annotation for validation? From what I understand, the values of any parameter (example StringLength min/max value) have to be truly static. Are...

Testing user role , Authorize attribute in VB.NET

Hi, I am using ASP.NET MVC to build a site. I am using VB as programming language.I have couple of questions. 1 I have created a role "Manager". How Do I check if a user belongs to this particular role? For now I am using If My.User.IsInRole("Manager") Then 'Direct to a view Else 'Direct to another view End If Is this the right wa...

Is it possible to create a custom ASP.NET MVC strongly typed HTML Helper?

Hello, I was wondering if it is possible to create a custom strongly typed HTML Helper in ASP.NET MVC 2? Creating a regular (read not-strongly-typed) helper is straightforward but i am having difficulty creating strongly typed versions. For example, I would like to create a DatePickerFor html helper... Any guidance or snippets would be ...