asp.net mvc

Hi Guys ,

I have some MVC app and I'm trying to return list  to the model view  and it is return 0. I'm wondering where i'm wrong.

Here is  how I wrote the code:

First I let user to click button and get popup window and pass id:

 function Showitems(id) {
            var url = "@System.Configuration.ConfigurationManager.AppSettings["webUrl"]";
            url = url + "Inventory/Itemsrefer/" + id;
            window.open(url, '_blank',"width=1200, height=800", 'resizable=No');
        }

Open in new window




My Controller:
public ActionResult Itemsrefer(int id)
        {
            mpsonCRMEntities db = new mpsonCRMEntities();

            var refi = (from i in db.t_InventoryCountEntry
                        join
                        e in db.t_InventoryCount on i.InventoryCountID equals e.ID
                        where i.InventoryCountID == id
                        select new Countitems
                        {
                         ItemID = i.ItemID,
                         Itemlookupcode = i.Itemlookupcode,
                         ItemDescription = i.ItemDescription,
                         CurrentInventory = i.CurrentInventory,
                         CountQty = i.CountQty
   
                        }).ToList();

            return View(refi);
        }

Open in new window




My View:
@model IEnumerable<ALThompsonCRM.Models.ViewModel.Countitems>

<div class="panel panel-default">
    <!-- Default panel contents -->
    <div class="panel-heading">
        Items Refers
        <div class="btn-group pull-right">
            @*<a class="btn btn-primary btn-sm" title="Update data" onclick="SaveAllItems();" href="#">Update</a>*@
        </div>
    </div>
    <div class="panel-body">
        <div id="table-content" class="table-responsive">
            <div id="content-table-inner">
                <div id="table-content">
                    <form id="poitems">
                        <table class="table table-bordered">
                            <tr style="background-color: silver;">
                                <th>ItemID</th>
                                <th>Item Description</th>
                                <th>Current Inventory</th>
                                <th> Count Qty</th>
                               

                            </tr>
                            
                            @foreach (var item in Model)
                            {
                                <tr>
                                    <td>@item.ItemID  </td>
                                    <td>@item.ItemDescription  </td>
                                    <td style="text-align: center">@item.CurrentInventory </td>
                                    <td style="text-align: center">@item.CountQty

                                </tr>
                                
                            }
                        </table>
                    </form>
                </div>

            </div>
        </div>
    </div>
</div>

Open in new window



Show on the 0 result in UI.


thanks ,
LVL 1
Moti Mashiah.NET DeveloperAsked:
Who is Participating?
 
kblauCommented:
got data:
default controller:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ReturnList.Controllers
{
    public class DefaultController : Controller
    {
        //
        // GET: /Default/

        public ActionResult Index()
        {
            return View();
        }

    }
}
-----------------
inventory controller
using ReturnList.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ReturnList.Controllers
{
    public class InventoryController : Controller
    {
        //
        // GET: /Inventory/

        public ActionResult Index(int id)
        {
            IList<Countitems> countItems = new List<Countitems>
            {      
                new Countitems{
                     
             
                     
                    CountQty = 5,
                    CurrentInventory = 33,
                    ItemDescription = "AHC",
                    ItemID = 1}
                ,
                new Countitems{
               
                    CountQty = 6,
                    CurrentInventory = 34,
                    ItemDescription = "AHCH",
                    ItemID = 2
                }
            };

            return View(countItems);
        }

    }
}
---------------------------------------
default view
@{
    ViewBag.Title = "Index";
}

<h2>Default</h2>
<script>
 function Showitems(id) {
            var url = "@System.Configuration.ConfigurationManager.AppSettings["webUrl"]";
            url = url + "Inventory/index/" + id;
            window.open(url, '_blank',"width=1200, height=800", 'resizable=No');
 }
    </script>

<input type="button" value="OpenWin" onclick="Showitems(1)" />
----------------------------
inventory view
@model IEnumerable<ReturnList.Models.Countitems>

<div class="panel panel-default">
    <!-- Default panel contents -->
    <div class="panel-heading">
        Items Refers
        <div class="btn-group pull-right">
            @*<a class="btn btn-primary btn-sm" title="Update data" onclick="SaveAllItems();" href="#">Update</a>*@
        </div>
    </div>
    <div class="panel-body">
        <div id="table-content" class="table-responsive">
            <div id="content-table-inner">
                <div id="table-content">
                    <form id="poitems">
                        <table class="table table-bordered">
                            <tr style="background-color: silver;">
                                <th>ItemID</th>
                                <th>Item Description</th>
                                <th>Current Inventory</th>
                                <th> Count Qty</th>


                            </tr>

                            @foreach (var item in Model)
                            {
                                <tr>
                                    <td>@item.ItemID  </td>
                                    <td>@item.ItemDescription  </td>
                                    <td style="text-align: center">@item.CurrentInventory </td>
                                    <td style="text-align: center">@item.CountQty

                                </tr>

                            }
                        </table>
                    </form>
                </div>

            </div>
        </div>
    </div>
</div>
--------------------------------
0
 
Moti Mashiah.NET DeveloperAuthor Commented:
Thank you very much for your answer, but I just figured that my code was just fine the only issue was the DB which I fixed.

Thank you soo much for help anyway. i will use your code for the next time.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.