asp.net-mvc-2

Render Partial of same name as parent View - Crashes WebDev.WebServer40.exe

柔情痞子 提交于 2019-11-30 19:10:08
问题 I'm wondering whether other people are having this same issue or whether it's just me ! Given I have a View Purchases.aspx and a partial view Purchases.ascx : Within Purchases.aspx if I do: Html.RenderPartial("Purchases") then WebDev.WebServer40.exe basically closes. I'm guessing that this is caused by a Stack Overflow because RenderPartial cannot determine what it's supposed to render (.aspx or .ascx). Is this a bug, is it a defined behaviour, or is it just happening for me? 回答1: It is

Having trouble with a simple MVC route

你说的曾经没有我的故事 提交于 2019-11-30 19:03:56
问题 Having some trouble with some routes. I don't fully understand the MVC routing system so bear with me. I've got two controllers, Products and Home (with more to come!). I want to have the views within the Home controller accessible without having to type Home in the url. Essentially I want to turn www.example.com/home/about into www.example.com/about, however I still want to preserve the www.example.com/products. Here's what I have so far. routes.MapRoute( "Home", "{action}", new { controller

Cannot insert explicit value for identity column in table 'ClientDetails' when IDENTITY_INSERT is set to OFF

你。 提交于 2019-11-30 18:45:45
I get this exception thrown whenever I try and submit data through a form to this database :- Exception Cannot insert explicit value for identity column in table 'ClientDetails' when IDENTITY_INSERT is set to OFF. However, the form doesn't have a field so data can enter the identity column (PK) so I'm at a loss as to why this is occuring. At the moment I'm using the standard asp.net mvc submit button but I will link it eventually to a jquery dialog button The ClientNo Column which is the said column the exception is referring to has the following attributes Name - ClientNo type - int NULLS -

Simple ASP.NET MVC views without writing a controller

我们两清 提交于 2019-11-30 18:42:42
We're building a site that will have very minimal code, it's mostly just going to be a bunch of static pages served up. I know over time that will change and we'll want to swap in more dynamic information, so I've decided to go ahead and build a web application using ASP.NET MVC2 and the Spark view engine. There will be a couple of controllers that will have to do actual work (like in the /products area), but most of it will be static. I want my designer to be able to build and modify the site without having to ask me to write a new controller or route every time they decide to add or move a

TempData persisting after read in ASP.NET MVC 2

心不动则不痛 提交于 2019-11-30 18:21:54
问题 In ASP.NET MVC 2, TempData values persist until the session ends or until they are read. In the words of Microsoft... The value of TempData persists until it is read or until the session times out. Persisting TempData in this way enables scenarios such as redirection, because the values in TempData are available beyond a single request. I thought I understood this but I just came across unusual behavior in my application where a TempData value was available and it should not have been

RadioButtonFor in ASP.NET MVC 2

拈花ヽ惹草 提交于 2019-11-30 17:58:27
Can someone provide a simple example of how to properly use Html.RadioButtonFor? Let's say it's a simple scenario where my model has a string property named Gender. I want to display two radio buttons: "Male" and "Female". What is the most clean way to implement this while retaining the selected value in an Edit view? Mac This question on StackOverflow deals with RadioButtonListFor and the answer addresses your question too (@Larsenal it also includes labels with the "for" attribute) Male: <%= Html.RadioButtonFor(x => x.Gender, "Male") %> Female: <%= Html.RadioButtonFor(x => x.Gender, "Female"

Custom ViewModel with MVC 2 Strongly Typed HTML Helpers return null object on Create?

陌路散爱 提交于 2019-11-30 17:53:11
问题 I am having a trouble while trying to create an entity with a custom view modeled create form. Below is my custom view model for Category Creation form. public class CategoryFormViewModel { public CategoryFormViewModel(Category category, string actionTitle) { Category = category; ActionTitle = actionTitle; } public Category Category { get; private set; } public string ActionTitle { get; private set; } } and this is my user control where the UI is <%@ Control Language="C#" Inherits="System.Web

format int to phone number

萝らか妹 提交于 2019-11-30 17:48:42
问题 Is there a way I can format for example: 0000000000 into (000)000-0000? I'm returning a listbox which holds a collection of phone number which arent formated yet. What I would like is format it. This is what I have in the View: <%= Html.ListBox("phoneList")%> and from the controller: ViewData["phoneList"] = new SelectList(phoneList); Edit $('#phoneList').each(function() { var phoneNumber = $(this).text(); var formatPhoneNumber = phoneNumber.replace(/(\d{3})(\d{3})(\d{4})/, '($1)$2-$3'); alert

Where does TempData get stored?

本秂侑毒 提交于 2019-11-30 17:20:46
Where does TempData get stored in the ASP.NET MVC Framework (more specifically, ASP.NET MVC 2)? Is it stored at server-side, or is sent to the client? By default TempData uses the ASP.NET Session as storage. So it is stored on the server ( InProc is the default). But you could define other ASP.NET Session state modes: StateServer and SqlServer. You could also write a custom TempData provider and handle the storage yourself if you don't want to use the ASP.NET Session. It is stored in session storage, but there is one crucial difference between TempData and Session : TempData is available only

How to specify date format for model binding?

别来无恙 提交于 2019-11-30 17:18:37
I hope the question is easy, but I am searching around for more than an hour and I just do not find the answer. So I have a asp.net mvc 2 application and one of the forms contains a date textbox with a jquery datepicker. I have set in the datepicker the date format to be dd.mm.yyyy . My problem is that on the model binding this date is interpreted as mm.dd.yyyy , so by the time the model reaches my action method the DateTime attribute of the model is not correct (day and month is reversed, if it is not possible to reverse it client side validation does not let me save the item). I do not want