Paul Stoner
Paul Stoner

Reputation: 1512

Serializing Model Data

EDIT

I am working on a project that will try to pre-approve customers for a credit card. This application

  1. Be called from a different application passing information about the customer
  2. Consume a wcf service that will do various things including calling a third party web service for the actual credit approval

This new system is being developed using ASP.NET MVC, to which I am extremely new.

So, I have the initial piece working, I can pass specific data to this mvc application and display the credit results to a view.

At this point, if the customer is approved, the user either needs to indicate if the customer wants to accept the offer or not. If they do, then the user needs to indicate which one,of four, credit card products the customer wants. If they want to generate an ACH payment, etc. If the customer declines the offer, the user has to select a reason for the decline.

OK, so all of that is working as well.

My problem lies in what to do if validation fails. I have specified several required if attributes for conditional validation. If the user forgets to select a credit card product, that would fail conditional validation if the customer accepted the offer. In these rare, yet conceivable, scenarios, I need to send the credit results, which include the card products offered, the decline reasons, customer name, etc.

So what I really need to understand is how can I send that credit response data back up to the controller I am using for the decision information.

The initial controller is simply called Index

[HttpPost]
public ViewResult Index ( PrescreenCCRequest request )
{
    WCFClient client = new WCFClient ( );

    PrescreenCCResult result = client.ProcessPrescreen ( request );

    return View ( result );
}

within the view for this controller I define a form for the various user options

@using ( Html.BeginForm ( "Save", "Prescreen", FormMethod.Post ) )
{
    ...Control definitions left out...
}

finally, the controller for the "Save" action:

[HttpPost]
public ActionResult Save ( PrescreenModel formData )
{
    if ( !ModelState.IsValid )
    {
        return View ( "~/Views/Prescreen/Index.cshtml", formData );
    }

    ... Additional Code left out ...
    return View ( );
}

So that is what I am working towards

Upvotes: 0

Views: 84

Answers (1)

IsakBosman
IsakBosman

Reputation: 1533

MVC Dll:

If you cannot find the dll when using the reference manager it sounds like MVC might not have installed correctly as they should be included in the Framework references. Here is what shows in my VS RM

I would suggest you look at installing MVC using the nuget package manager that is built into Visual Studio

enter image description here

Persisting Data Across Controllers:

This is a topic on its own and has various approaches. It depends on many factors like how long you would like the data to be persisted etc.

If there data is persistence is fairly short lived I would use the Session object or the TempData object when accessing it across requests.

Serializing Data:

What format is the data? If it is in Json I would recommend using the NewtonSoft as this has a very flexible object serializer/deserializer that can be used to validate object data into custom data models.

Upvotes: 1

Related Questions