-1

I tried to put the code as MVC c# form from console. I want to show key with account, meter numbers, but I have no idea what I'm wrong. What I want to try is that prints out all info in Details page.

Here is controller

 public ActionResult Index()
    {
        return View(db.fedex.ToList());
    }

    private static RateRequest CreateRateRequest()
    {
        FedexModel fedex = new FedexModel();

        // Build a RateRequest
        RateRequest request = new RateRequest();
        //
        request.WebAuthenticationDetail = new WebAuthenticationDetail();
        request.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential();
        request.WebAuthenticationDetail.UserCredential.Key = fedex.AccessKey; // Replace "XXX" with the Key
        request.WebAuthenticationDetail.UserCredential.Password = fedex.Password; // Replace "XXX" with the Password

        //
        request.ClientDetail = new ClientDetail();
        request.ClientDetail.AccountNumber = fedex.AccountNumber; // Replace "XXX" with the client's account number
        request.ClientDetail.MeterNumber = fedex.MeterNumber; // Replace "XXX" with the client's meter number

        //
        request.TransactionDetail = new TransactionDetail();
        request.TransactionDetail.CustomerTransactionId = "***Rate v14 Request using VC#***"; // This is a reference field for the customer.  Any value can be used and will be provided in the response.
        //
        request.Version = new VersionId();
        //
        request.ReturnTransitAndCommit = true;
        request.ReturnTransitAndCommitSpecified = true;
        //
        //SetShipmentDetails(request);
        //
        return request;
    }

    //
    // GET: /Fedex/Details/5

    public ActionResult Details(int id = 0)
    {
        var request = CreateRateRequest();

        return View(request);
    }

If I click the key then it goes to next in Details page.

Details View

@model FedExShipping.Models.FedexModel

@using FedExShipping.WebReference;
@using FedExShipping.Controllers;

<h2>Details</h2>

<fieldset>
<legend>FedexModel</legend>

<div>
    @Html.DisplayFor(model => model.AccessKey)
</div>
<div>
    @Html.DisplayFor(model => model.Password)
</div>
<div>
    @Html.DisplayFor(model => model.AccountNumber)
</div>
<div>
    @Html.DisplayFor(model => model.MeterNumber)
</div>

What do I need to change for correct output?

J.K
  • 89
  • 1
  • 2
  • 9
  • 2
    what is your expected behaviour ? – Shyju Aug 22 '14 at 18:19
  • A web application has no "console". I suppose the closest thing would a log file in IIS, but I'm not sure if IIS will intercept calls to `Console.Write` and write it to a log file. If you want to "log" something for testing purposes (which seems to be what you're trying to achieve), then either print it directly in the generated HTML or use a true logging solution. – Chris Pratt Aug 22 '14 at 18:28
  • In Create view, I entered key, password, acct #, meter #, and In index view, If I click key, then it will go to Details page. What I'm trying to do is that I want to pass the all four values into Details page and show what the values are. But, this kind of approach is not working. – J.K Aug 22 '14 at 18:33
  • I'm trying to move original Console application to MVC C# web application form. I'm not sure what I need to do to make this working successfully. – J.K Aug 22 '14 at 18:35

1 Answers1

0

Your action is returning View(request) so your model is being set to RateRequest. Which means your view for this action is interacting with RateRequest, not FedexModel. You can interact with anything that's set on your instance of RateRequest only. If you need something else, you need to change the model for the view and pass something other than an instance of RateRequest to it.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444
  • What you are saying is that I don't need RateRequest? Is it available to process without RateRequest by only using FedexModel? I think that it is to pass the information to go next step. Could you give me some examples for that? – J.K Aug 22 '14 at 18:58
  • I'm saying what you pass to your view and the defined model for your view should align. If you want to work with FedexModel then instatiate one, fill it with data and then pass it to a view that can work with it. – Chris Pratt Aug 22 '14 at 19:00