MVC :: Compound View Model Object Causing Remote Validation Failure?

Feb 12, 2011

I have used a pattern of compound view models for a few of the forms in this project. It works very well.

In this case I have a VendorAddress view model. I use Address(es) in a few places in this project so I made and Address view model object that I can re-use. Then I desided I want to do a very thorough checking of the state codes and zips so, I desided I would try to use remote validation and check the state and zip code aganst a stored set of tables in the database.

The problem is I am not getting values back to the remote action methods for the fields I'm asking for (in this case State and PostalCode). I believe this is because of the name mangleing that the MVC framework does for compound or sub types for id(s) for the inputs in this case it is making names like 'Address_Line1' and 'Address_State' and 'Address_PostalCode'.

Ultimately the question I have is, is there a way of turning off the pre-pended 'Address_' from the base view model object in a way that MVC framework can put it bak into the object after ther post of the form?

[Code]....

Then in the form after rendering it looks like this:

[Code]....

I get the remote call but there is nothing in the parameters "State" and "PostalCode", so the unobtrusive routines are firing but I think it does not know where to look for the data even though I have type something in the mensioned fields. As you can see in the rendered code the id="Address_State" and the data-val-remote-additionalfields="*.State,*.PostalCode"

View 4 Replies


Similar Messages:

Configuration :: DLL Failure Causing "Object Reference Not Set To An Instance Of An Object." - How To Fix It

Jun 23, 2010

i don't know how far I'm going to get with this considering that I'm pulling together this API for a payment gateway that's isn't very well supported by the developers who supplied it, but...

I'm getting an "Object reference not set to an instance of an object" error on this:

' Put user code to initialize the page here

View 3 Replies

MVC :: EF - Nullreferenceexception In View. Handle Non Existing Object References In View Model

Mar 15, 2011

I have an entity object as model input in my view. Not sure if it's the best approach, but I use the object references to get values from a related object.Let's say I've got a car entity and a manufacturer entity.Here's how it would look in my view

[Code]....

I've get a nullreferenceexception where the car entitity does not have a reference towards manufacturer. I'd like to output a " " if no manufacturer exists.

View 4 Replies

MVC :: Passing Model Object To View And From View To Controller?

Aug 6, 2010

I've got problem with my app .

I've got such classes (this is some kind of tree structure):

[Code]....

[Code]....

in Index() action i've got this piece of code

[Code]....

[Code]....

View 2 Replies

MVC :: Multiple Model Validation In Same View?

Jul 10, 2010

I have a Order view with 2 user controls in it.

The first user control in the view is just to validate the customer and get some more details about the customer. This control is having one text box (customer name) with the button. When the user clicks the button it should validate the customer name in the client side using data annotations of customer model. if validation success then it should use some bussiness logic to verify the customer and show the customer details on the form.

The 2nd user control in the view is to get the address of the customer by searching for the house no and the postcode. This control is having 2 text box with the button.

The first user control is based on the strongly typed customer entity

The 2nd user control is bsed on the strongly typed address entity

The view with both the user control is based on the strongly typed order entity.

The issue here is with the validation. I have the validation summary in the view and client sider validation is enabled. When i click the search button on the first user control the client validation starts and throws validation error messages because when i search for the customer at that point of time i will not have values to may of the customer related fields in the order view.

The same thing happen when i click the search button on the 2nd view. It will throw client side validation for other fields.

What i want to achive is that when the user click the search button on the user control 1 then the validation should happen only to the customer name field (both in client and server).

When the user click the search button on the 2 nd user control the the validation should happen only for houseno and the postcode both in client and the server.

When the user clicks the save button on the order view all the fields in the form even the controls usere input fields should get validated. How to achive this in mvc?

View 4 Replies

Repopulate The View Model In MVC 2 After A Validation Error?

Mar 15, 2010

I'm using ASP.NET MVC 2 and here's the issue. My View Model looks something like this. It includes some fields which are edited by the user and others which are used for display purposes. Here's a simple version

public class MyModel
{
public decimal Price { get; set; } // for view purpose only
[Required(ErrorMessage="Name Required")]

[Code]....

But doing this, I get an error on UpdateModel(rec): The model of type 'MyModel' could not be updated.

View 3 Replies

MVC :: Dropdownlist Validation Not Working For Complex View Model

Feb 3, 2011

I have a question regarding validation of drop-down list values. I have a view that is bound to a view model type called ReservationData.

This object contains a property CustomerVehicles of type List<VehicleData>. VehicleDatahas two int properties VehicleMakeId and VehicleModelId.

On my view I am trying to loop over the number of items in the CustomerVehicles collection and displaying two dropdowns for each, a vehicle make dropdown and a vehicle model dropdown usingDropDownListFor.

When I try to submit and validate I do not see any validation errors displayed on the screen.

Just in case you are wondering I have added a ValidationMessageFor for each dropdown as well. I am not sure if this is an issue with the structure of my view model and its complexity and how the controls need to be named or how the ids need to be set.

Here is the code for the looping over the collection:

[Code]....

View 11 Replies

MVC :: Multiple Instances Of Same Partial (with Same View Model) Messes Up Validation?

Jan 27, 2011

This project I'm working on have this custom clientside JavaScript validation framework created for (which I cannot change) that show error messages/summary based on your data annotations and a "Validate" method in your ViewModel.

Like I said I'm not allowed to change this, so wont be able to go with suggestions doing that.

What the person that created this did not foresee, is that one might need put several partials of the same type and having the same view model (each in a form) on a view.

So I went ahead and did things the normal way (using Html.whateverFor<model => model.whatever) and wala!....the custom validation thing throws error messages for the specific form fields, next to each form in the view. I was suggested to create a "prefix" for each instance of the view model, and do something like this:

Change: <%: Html.HiddenFor(model => model.AccountNumber)%>

To: <%: Html.Hidden(Model.ElementPrefix + "AccountNumber", Model.AccountNumber)%>

Not to mention the tons of jquery selectors and all that I have to go change (and all my view inputs)

(I just hate having to find workarounds for this "custom" everything they created for this project)

View 9 Replies

C# - MVC View Model Text Data Lost After The Post - Display Them In The Case Of Failed Validation?

Nov 12, 2010

I've got a view model that has some text properties. And I use Html.DisplayFor to display them on the screen. But those text data won't be post back, so in the case of failed validation, the returned view won't have those data. How do I handle this kind of situation?

View 2 Replies

SQL Server :: Database Restore Failure On Remote Host?

Mar 12, 2011

I'm getting an error in Parallels Plesk for SQL Server database on restore the cause of which is a mystery to me. Here is the support ticket I sent my hosting company:

I'm in the process of restoring my databases and the first one restored just fine. The second one called ***** for *****.com failed with the following error:

Error: dbbackup failed: Unable to restore database 'alienreports' Not valid backup The media family on device C:WINDOWSTEMPlocalhostalienreports*******.bak' is incorrectly formed. SQL Server cannot process this media family. VERIFY DATABASE is terminating abnormally.

This happened both when using the .bak file from my old host and after restoring that file on my local machine using SQL Server Management Studio 2008 just fine before backing it up and getting the same error when trying to upload and restore.

View 7 Replies

Diagnose A Failure In The Membership Service On Remote Site?

Apr 17, 2010

Yesterday I added a custom MembershipProvider to an ASP.NET web application, but when I deployed the application to its remote host server, it failed. I know I had the login info correct, and I also know that for nearly any exception in the login process, the Login control displays the standard error message, "Your login failed", so I assume something is wrong in the code/config.

What can I do to diagnose what is wrong on the server?

BTW: This weekend I only have FTP access to the server, so no event log, and CustomErrors is already set to Off.

THE END: I was an idiot, and using the wrong query window to check if the my login actually existed on the server.

View 1 Replies

Model View Control Versu Model View Presenter

Jun 2, 2010

I have been reading about different model for development

model view control mvc

model view presenter MVP

Model view view model MVVM

i belive MVC has two big Advantage over webform 1) TDD 2) More control on HTML

MVP is bit variation in mvc model. rapid development as well as 1) TDD 2) More control on HTML (correct me if i m wrong) see the below link

[URL]

View 7 Replies

MVC :: Access Model Validation Inside Custom Model Binder?

Sep 1, 2010

Is it possible, inside a Custom Model Binder, to fire "something" that "says" the value is invalid so it gets handled by validation part?

Basically, I am getting an exception when the value for the property is invalid.

View 1 Replies

Web Forms :: Prevent Enter From Causing Validation?

Aug 3, 2010

I have an HTML text box and button:

<input type='text' onkeypress='onEnter(this, event);' />
<input type='button' />

This works fine (when you push enter, another function is called) unless the page has a FormView control on it.

In this case, pushing Enter in the textbox above attempts to validate the form on the page. It will still correctly call the onEnter function, but I need the Enter keypress to not cause Validation of any other forms on this page.

All input fields in the FormView are part of a ValidationGroup, but this doesn't seem to affect anything.

What is the best way to keep the .Net validation from happening when I push Enter in my HTML textbox?

View 4 Replies

Access Office Word Object Model Through Asp Results - Error 80070005 - COM Object Not Registered

Aug 13, 2010

I have developed a website that allows users to upload office documents then uses the office object model to convert the document to an HTML file that it then displays in an iFrame. I have, of course, included references to Office.interop.word, and the site works fine on my development machine. When I uploaded it to my production server the site functions fine until I try to upload a document. I initially got a similar error that said "COM object not registered". I realized that Word wasn't installed on my production server. So I installed word and now when the server tries to access the word object model I receive the following error:

Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

I searched the registry for the corresponding CLSID and found a corresponding folder. I added full control to the IUSR_ account and due to the persistence of the error I eventually added full control to "everyone" and ensured these permissions inherited down to the rest of the folder. I then added full control to IUSR_ and again eventually added full control to "everyone" to my microsoft office folder. I don't know what other permissions to grant and where in order to make this "Access is denied" error go away. I must be granting them in the wrong place, because as far as I know I can't be any more permissive than "Everyone" "Full Control".

View 1 Replies

MVC :: Validation Of Model In Side Model

Oct 12, 2010

I have recently started working on ASP.NET with MVC 2 framework, and I am facing following difficulty in validating my data,

Scenario:

In my application the view (ASPX) is divided into tabs (jQuery) and each tab's content is ViewUserControl (ASCX). The main model for the view has collection of sub models for individual tabs. I use RenderPartial method to render view user control.

[Code]....

And the user control (Tab1.ascx) refers the specific model for it,

[Code]....

Now if in my Tab1Model if I put following validation

[Code]....

In the controller ModelState.IsValid is always indicates TRUE. How do I override the validation behavior such that it as well looks the items in the collection member (which holds sub models) as well.

<%= Html.ValidationMessage("FirstName") %>

View 1 Replies

Web Forms :: Button Causing Validation Inside A RadWindow?

Jan 8, 2011

I have a form that when you click a button, an ajax RadWindow opens with a text box and a button so it can scrape information from another web page. I have set the button that causes the postback to CausesValidation="False", but after it does the postback after loading the scraped information into other controls, it still causes validation to fire.

how to make it not fire the validation?

View 4 Replies

Web Forms :: URL Rewriting Causing Validation Of Viewstate MAC Failed?

Nov 22, 2010

Has anyone encountered while using Context.RewriteUrl in global.asax causes this error: Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster ?

Here is the scenario, let's say I have a url

http://mysite.com/admin/login.aspx instead typing the whole url in address, user can type either
http://mysite.com/admin/ or http://mysite.com/admin which all end up at http://mysite.com/admin/login.aspx. When a user type http://mysite.com/admin and entered correct login info, and press login button it gets the error above. How can I resolve this? Tried setting EnableValidateRequest to false and EnableViewstateMac to false also even I do not want to use this approach and still does not work.

View 5 Replies

Should Data Annotations Be On The Model Or The View Model

Dec 15, 2010

I've been used to decorating data model classes with data annotation attributes, but the purist in me baulks slightly at including purely presentational attributes such as display format here. I am, however, quite happy to keep validation centric attributes here. One good reason I have to continue keeping all annotations etc. in the data model is that my view model aggregates data model classes, e.g.

my ViewModelBase.DetailItem<TEntity> property in the view model is just a reference to an entity class in my data model. If I wanted to move presentational annotations to the view model, I would have to quite radically revise my design to one where I duplicate data model properties in my view model and use an object mapping tool to populate view model objects based on data model objects.

[code]....

View 2 Replies

MVC :: View Model To Convert To Domain Model?

May 4, 2010

Say I got a domain model as follows: (and my repository expect an instance of this object)

[Code]....

And a view model (which my views are based on)

[Code]....

At the moment I got it like this and have my controller action manually create a new Person object from the PersonModel object before passing it on to the repository, which does not feel right.

So I tried to have PersonModel inherit from Person and pass that to the repository (also tried casting the PersonModel to a Person object first), but that don't work out.

What's the right way to have PersonModel automatically cast to Person? I want to keep this logic as my current structure allow me to keep things really loosely coupled, with the repository layer not having a clue how it's being used.

View 1 Replies

Web Forms :: Date Validation Causing Multiple Error Messages?

Jan 7, 2010

When i click on the Search Button OR the Count Button, i get BOTH error messages - why ? I should only get one error message.

[Code]....

View 22 Replies

ADO.NET :: Simple Databinding With LINQ Causing Object Reference Not Set?

Aug 15, 2010

I have a user control with a datalist. I just want to do some simple binding but keep getting an object reference not set to an instance of an object error. The following is the code, I am sure I am just missing something simple:

Dim dc As Forms.DataClassesDataContext = New Forms.DataClassesDataContext
Dim formQuery = From fq In dc.v_form_questions _
Where fq.FormTypeID = FormTypeID _

[code]...

When I debug, I see values for the formQuery; I am also able to loop through the formQuery and response.write a field out, however every time I try to bind it to a databound control, I get the Object reference not set to an instance of an object error.I initally was using a simple LinqDataSource object, but needed to set the where parameter to the FormTypeID property of this usercontrol. I had a Where condition defined on Page Init, but started getting the object reference error.

View 1 Replies

Web Forms :: LinkButton Not Causing Validation Inside UpdatePanel (normal Button Does Though)

Jan 30, 2011

I am using a MultiView inside an UpdatePanel with several views within it and a button on each that is supposed to validate the controls on the current view before moving onto the next view in the sequence (a bit like the Wizard control except I wanted more freedom).

I am using an LinkButton but the problem is that the LinkButton is not causing validation -- I have also tested with an ImageButton which isn't causing validation either. However, when I use a normal Button, the validation does work. I have grouped my validation controls into a ValidationGroup and made sure that CausesValidation is turned on.

[Code]....

View 2 Replies

Web Forms :: Create Via C# In An Event Causing Page Validation To Occur On Postback?

Feb 14, 2011

I'm having trouble with an image button I create via c# in an event causing page validation to occur on postback. The CausesValidation attribute is set to false at time of creation in the event. I also wire up the Click event in the page_init with postback so not to loose the event handler if the page posts another way. Here is the code I'm using in the click event of a Button. I've also tried to enable and disable viewstate for the button with no luck. What am I missing here that continues to fire page validation in the Click of this imagebutton?

[Code]....

View 2 Replies

Web Forms :: Dynamically Add Object In Page Causing Second Postback With Ispostback?.

Jan 17, 2011

I dynamically add the webcontrol in onInit or onload (page_load). it will cause the second post back and with the ispostback==false;

if first enter the page is no problem. but if I click on the some button. it will trigger postback two times.

first time: ispostback = true.

second time: ispostback = false.

the second time postback caused me headache because all my value has been initialized due to the coding like below:

DataTable _temp;

if(! ispostback)

[Code]....

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved