asp.net-mvc-2

ASP.NET MVC2 - specific fields in form pass via a specific object?

亡梦爱人 提交于 2020-01-15 09:41:30
问题 In database I have Contacts table: ContactID (int) FirstName (varchar) LastName (varchar) ... XmlFields (xml) // This field is xml type To create a new contact, I created two classes - one for regular fields and other to display fields from XmlFields field. In Controller, I have following: public ActionResult Create(Contact contact, FormCollection collection) ... Regular field I catch with contact object and those that need to be stored as xml in XmlFields I try to catch with collection

ASP.NET MVC: How to execute Data Annotation validations in the service layer?

╄→гoц情女王★ 提交于 2020-01-14 10:34:15
问题 In a recent question posed here: ASP.NET MVC: Is Data Annotation Validation Enough? ...it was concluded that relying on data annotation validation (triggered by the model binder) was not enough to ensure that validation was always executed. We still need to add the same validation logic in the services layer (or somewhere else after ModelBinding happens). The unfortunately thing about this is that we will be duplicating our validation code (once with Data Annotations and again in the services

Why DisplayFor does not post values to Action Method?

孤街醉人 提交于 2020-01-14 10:26:08
问题 When we post the form using below to Action Method, we can see the View Model values in Parameter. @Html.EditorFor(model => model.Foo) When we post the form using below to Action Method, we can't see the View Model values in Parameter. @Html.DisplayFor(model => model.Foo) So, in later case, w could us Hidden Fields. So, I think, w should not us DisplayFor when it comes o post form values. Question : Why DisplayFor does not post values to Action Method? Can we discuss the internal mechanism

Persisting complex data between postbacks in ASP.NET MVC

只愿长相守 提交于 2020-01-14 09:15:51
问题 I'm developing an ASP.NET MVC 2 application that connects to some services to do data retrieval and update. The services require that I provide the original entity along with the updated entity when updating data. This is so it can do change tracking and optimistic concurrency. The services cannot be changed. My problem is that I need to somehow store the original entity between postbacks. In WebForms, I would have used ViewState, but from what I have read, that is out for MVC. The original

'object' does not contain a definition for 'Name'

北城以北 提交于 2020-01-14 09:10:06
问题 I'm using two DataContext objects to return seperate AsQueriable() datasets then joining the two using linq. The data construction works perfectly however when I pass that combined dataset to the view, I'm getting the error 'object' does not contain a definition for 'Name'. During a debug session I can clearly see that both the parent Model and each 'item' in the foreach loop has all the data and keys visible/accessible. I'm very confused. Many of the other q&a's on stackoverflow.com that

Error on MVC application debug : Validation of viewstate MAC failed

落爺英雄遲暮 提交于 2020-01-14 07:19:32
问题 Starting form now, for the first time, I am getting this error when I start debugging my MVC application Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster. Full stack trace [ViewStateException: Invalid viewstate. Client IP: 127.0.0.1 Port: Referer: Path: /Login/LogOn User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US)

Controller AJAX method to return AJAX ActionLink

老子叫甜甜 提交于 2020-01-14 05:59:09
问题 I am fairly new to MVC and just trying to achieve something which I think shouldn't be too complicated to achieve. Just want to know what the best approach for that is. I have an Event-RSVP application (NerdDinner kind) where you go to view details of the event and then click on an AJAX link that will RSVP you for the event. <% if (Model.HasRSVP(Context.User.Identity.Name)) { %> <p> You are registered for this event!  <%: Ajax.ActionLink("Click here if you can't make it!", "CancelRegistration

Create new database programmatically in Asp.Net MVC application?

喜你入骨 提交于 2020-01-13 19:18:30
问题 I have worked on a timesheet application application in MVC 2 for internal use in our company. Now other small companies have showed interest in the application. I hadn't considered this use of the application, but it got me interested in what it might imply. I believe I could make it work for several clients by modifying the database (Sql Server accessed by Entity Framework model). But I have read some people advocating multiple databases (one for each client). Intuitively, this feels like a

ASP.NET MVC2 - Render a View as a String

点点圈 提交于 2020-01-13 06:23:27
问题 How do you render a view as a string from a controller in MVC 2? In MVC 1, I used CaptureActionHtml. I'm having the same problem with it as a similar question, but is there a way to do this without Rhink.Mocks? 回答1: I've found Steve Sanderson's Integration Testing framework to work out very well for this. Perusing one of the code samples from his own blog post gives you some idea of the capabilities of the framework, the assertions that you can perform against its output, etc: [Test] public

Dynamic validation on MVC 2

被刻印的时光 ゝ 提交于 2020-01-13 05:25:14
问题 This works fine [MetadataType(typeof(Area_Validation))] public partial class Area { ... } public class Area_Validation { [Required(ErrorMessage = "Please add this field.")] public int Email { get; set; } [Required(ErrorMessage = "Please add this field")] public string Name { get; set; } } but how about if Area_Validation is dynamically created ? for example Subscription Fields that on back-end can be created by the user and end up like this: How can I set the Metadata on each field for auto