Do I need to use the same VM in the POST, as the GET, to reload index?

John

Using MVC, in the GET function in the controller I am creating the VM and passing it to the view.

[Themed]
public ActionResult OrderManufacturedProducts(int id)
{   
     QBProductRecord QBproduct = _qbproductService.GetById(id);

     OrderManufacturedProductsVM model = new OrderManufacturedProductsVM(QBproduct);

     return View(model);
}

Then The View:

@model System.ViewModels.OrderManufacturedProductsVM
@{
    Script.Require("ShapesBase");
    Layout.Title = T("Manufactured Orders").ToString();
}

@using (Html.BeginFormAntiForgeryPost())
{
<fieldset>
    <table class="items" summary="@T("This is a table of the manufactured products to be ordered")">
        <colgroup>
            <col id="Col1" />
            <col id="Col2" />
            <col id="Col3" />
        </colgroup>
        <thead>
            <tr>
                <th scope="col">&nbsp;&darr;</th>
                <th scope="col">@T("Name")</th>
                <th scope="col">@T("Description")</th>
            </tr>
        </thead>
        <tbody>  
            <tr>
                <td>@Model.QBProduct.ProductName</td>
                <td>@Model.QBProduct.StockLevel</td>
                <td><input id="Order" name="NoToOrder" type="text" value="0" onchange=""/></td>
            </tr>
        </tbody>
    </table>

     <div class="align right"><button type="submit" name="command" value="Save">Order</button></div>
</fieldset>
}

So the user enters a order no. in the input field and clicks submit which returns to the post.

[HttpPost, ActionName("OrderManufacturedProducts")]
public ActionResult OrderManufacturedProductsPOST(int id, int NoToOrder)
{
// OrderManufacturedProductsVM model = new OrderManufacturedProductsVM(QBproduct);
// return View(model);

return Index();
}

I want to return to the Index page, but it is telling me

Server Error in '/OrchardLocal' Application.
The model item passed into the dictionary is of type 'System.ViewModels.ManufacturedProductsVM', but this dictionary requires a model item of type 'System.ViewModels.OrderManufacturedProductsVM'.

So do I need to use the same VM in my post? all I want to do is reload the index page after the update is made.

NOTE: the update on the record is working fine, I just cant get the correct page to display after.

musefan

In your OrderManufacturedProductsPOST action, you should redirect to the action you want to return. Like so:

[HttpPost, ActionName("OrderManufacturedProducts")]
public ActionResult OrderManufacturedProductsPOST(int id, int NoToOrder)
{
    // OrderManufacturedProductsVM model = new OrderManufacturedProductsVM(QBproduct);
    // return View(model);

    return RedirectToAction("Index");
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Do I need to create same list for both get/post ActionResult?

From Dev

Do I need a critical section to get the index of a value in a stringlist?

From Java

Why do I need to reload my page to get data from a subjectSubscription in Angular?

From Dev

How do I get the index of multiple occurrences of the same character in a string?

From Dev

Why do I need to use port forwarding to be able to access SFTP on my VM?

From Dev

Do I need to use fetch() to get a Parse.com query?

From Dev

In Firebase Firestore, I want to use orderBy twice. Do I need to create an index to speed up the query?

From Dev

Do I need to use callbacks?

From Dev

Do I need to use IDisposable?

From Dev

How do I use indexOf to get the index of a selected NSCollectionView?

From Dev

Why I get [Laravel - Undefined variable: users (View..] if I tried to use POST and GET on the same view?

From Java

Why do I need to use dynamic memory allocation when I can achieve the same from static?

From Dev

laravel do I need index() on unique() column?

From Dev

Do I need to reset a Perl hash index?

From Dev

Do I need to add bootstrap.min.css in index.html to use ng-bootstrap?

From Dev

Do I need to add bootstrap.min.css in index.html to use ng-bootstrap?

From Dev

Do I need to use both isset() and $post_variable="value"? Why not just the latter?

From Dev

Do I need variable and property at the same time?

From Dev

Why do I need to use dup for stdout redirection if the same can be achieved without it?

From Dev

How do I get into a Docker container, start a vpn and use my webbrowser just like a VM

From Dev

Why do I need to join a thread even if I use std::future::get?

From Dev

Do I need to use random.seed() with random.uniform() to ensure I get different sequences

From Dev

How do I get the information I need in order to use unison and ssh to synchronise files

From Dev

Is it possible to use both GET and POST in a same method?

From Dev

Is it possible to use both GET and POST in a same method?

From Dev

Submitting a Form Action Post for API, do I need a post route?

From Dev

I have 2 form on same page and i need the submit button to send the information to the right app.post in express.js, how do i do it?

From Dev

How do I get multiple post requests from Django and Ajax on the same page working?

From Dev

Can I use a Dual Boot and VM with the same installation?

Related Related

  1. 1

    Do I need to create same list for both get/post ActionResult?

  2. 2

    Do I need a critical section to get the index of a value in a stringlist?

  3. 3

    Why do I need to reload my page to get data from a subjectSubscription in Angular?

  4. 4

    How do I get the index of multiple occurrences of the same character in a string?

  5. 5

    Why do I need to use port forwarding to be able to access SFTP on my VM?

  6. 6

    Do I need to use fetch() to get a Parse.com query?

  7. 7

    In Firebase Firestore, I want to use orderBy twice. Do I need to create an index to speed up the query?

  8. 8

    Do I need to use callbacks?

  9. 9

    Do I need to use IDisposable?

  10. 10

    How do I use indexOf to get the index of a selected NSCollectionView?

  11. 11

    Why I get [Laravel - Undefined variable: users (View..] if I tried to use POST and GET on the same view?

  12. 12

    Why do I need to use dynamic memory allocation when I can achieve the same from static?

  13. 13

    laravel do I need index() on unique() column?

  14. 14

    Do I need to reset a Perl hash index?

  15. 15

    Do I need to add bootstrap.min.css in index.html to use ng-bootstrap?

  16. 16

    Do I need to add bootstrap.min.css in index.html to use ng-bootstrap?

  17. 17

    Do I need to use both isset() and $post_variable="value"? Why not just the latter?

  18. 18

    Do I need variable and property at the same time?

  19. 19

    Why do I need to use dup for stdout redirection if the same can be achieved without it?

  20. 20

    How do I get into a Docker container, start a vpn and use my webbrowser just like a VM

  21. 21

    Why do I need to join a thread even if I use std::future::get?

  22. 22

    Do I need to use random.seed() with random.uniform() to ensure I get different sequences

  23. 23

    How do I get the information I need in order to use unison and ssh to synchronise files

  24. 24

    Is it possible to use both GET and POST in a same method?

  25. 25

    Is it possible to use both GET and POST in a same method?

  26. 26

    Submitting a Form Action Post for API, do I need a post route?

  27. 27

    I have 2 form on same page and i need the submit button to send the information to the right app.post in express.js, how do i do it?

  28. 28

    How do I get multiple post requests from Django and Ajax on the same page working?

  29. 29

    Can I use a Dual Boot and VM with the same installation?

HotTag

Archive