The official release of Ext.NET Mobile is now available. Ext.NET Mobile is an ASP.NET component framework for building Phone and Tablet specific mobile web applications. Read More

Please help me ASP.Net MVC add item to store in controller

  1. #1

    Please help me ASP.Net MVC add item to store in controller

    I have DirectEvent
            public ActionResult AddItemToDetails(long lookupItemId, String viewBagID, int posLinesCount)
                var itemRepository = new ItemRepository();
                var item = itemRepository.Get(c => c.Id == lookupItemId, new []{ "BaseUom" }).SingleOrDefault();
                Store posLineStore = X.GetCmp<Store>("posLineStore" + viewBagID);
                int lineNo = posLinesCount <= 0 ? 1 : posLinesCount + 1;
                var newItem =  new PosLineEditViewModel() { ItemId = item.Id, Description = item.Description, LineNo = lineNo, Quantity = 1, UnitPrice = 1, Amount = 1, UomId = item.BaseUomId, UomDescription = item.BaseUom.Description, Id = 2};
                return this.Direct();
    Here is my error

    Uncaught TypeError: Cannot read property 'add' of undefined
    at eval (eval at executeScriptDelay ...
    Last edited by anh34; May 29, 2018 at 5:20 AM.
  2. #2
    Hello @anh34! And welcome to Ext.NET forums.

    I believe you want to add to a store a record and not a ViewModel, as your code suggests.

    But that's as far as I can go with the information you provided. We may be able to help you if you provide a runnable code sample. Please review our guidelines for making requests we can actually help you with:
    - Tips for creating simplified code samples
    - More Information Required
    - Forum Guidelines

    As a base for your test case, it may be a good idea to use one of our examples in Examples explorer... Maybe a good one to start with would be the Simple GridPanel one. As for MVC, you can merge the Model code with the Controller to simplify it even more.

    Doing that, we should be able to copy-paste your code in a clean project, see what exactly is happening, and suggest, code-wise, on what you can do to overcome the difficulty.

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3

    Thanks you for support me. Here is my Example

    Thanks you for support me. Here is my Example

    @using Ext.Net;
    @using Ext.Net.MVC;
    @model ExtNet_Example1.Models.ExtNetModel
        Layout = null;
    <!DOCTYPE html>
        <title>Ext.NET MVC Sample</title>    
        <link type="text/css" rel="stylesheet" href="" />
        @( Html.X().Viewport()
                                       .TabBar(components =>
                                           components.Add(Html.X().Button().Flat(true).Icon(Icon.Add).DirectEvents(de =>
                                               de.Click.Url = Url.Action("AddTab");
                                               de.Click.ExtraParams.Add(new { containerId = "POSTabs" });
                                               de.Click.EventMask.ShowMask = true;
    @using Action = System.Action
    @model ExtNet_Example1.Models.ExtNetModel
        Layout = null;
        String posPanelId = "POSPanel" + ViewBag.ID;
        String addItemButtonId = "AddItemButton" + ViewBag.ID;
        String posLineGridPanel = "PosLineGridPanel" + ViewBag.ID;
        String posLineStore = "PosLineStore" + ViewBag.ID;
              .Title("POS - " + DateTime.Now.ToLongTimeString())
                      .Defaults(Html.X().Parameter().Name("margin").Value("0 5 0 0").Mode(ParameterMode.Value))
                      .LayoutConfig(new HBoxLayoutConfig { Align = HBoxAlign.Top })
                                Html.X().Button().ID(addItemButtonId).Icon(Icon.ArrowDown).DirectEvents(de =>
                                    de.Click.Action = "AddToDetails";
                                    de.Click.ExtraParams.Add(new Parameter("lookupItemId", "TEST", ParameterMode.Value));
                                    de.Click.ExtraParams.Add(new Parameter("viewBagID", ViewBag.ID));
                                    new ModelField("Title", ModelFieldType.String)
    public class ExtNetController : Controller
            public ActionResult Index()
                return this.View();
            public ActionResult AddTab(string containerId)
                var model = new ExtNetModel();
                var result = new Ext.Net.MVC.PartialViewResult
                    ViewName = "TabPartialView",
                    ContainerId = containerId,
                    RenderMode = RenderMode.AddTo,
                    ViewData = ViewData,
                    Model = model
                result.ViewBag.ID = DateTime.Now.Ticks.ToString();
                return result;
            public ActionResult AddToDetails(string lookupItemId, String viewBagID)
                var newItem = new ExtNetModel()
                    Title = lookupItemId
                Store posLineStoreID = X.GetCmp<Store>("posLineStore" + viewBagID);
                posLineStoreID.Add(newItem); //<---- error here
                return this.Direct();
    Here is error
  4. #4
    Please Closed it is my failed. ViewBag.ID is long and will be round in javascript.

    I have changed

    de.Click.ExtraParams.Add(new Parameter("viewBagID", ViewBag.ID));

    de.Click.ExtraParams.Add(new Parameter("viewBagID", ViewBag.ID, ParameterMode.Value));
    and it work now.

    Last edited by anh34; Jun 01, 2018 at 6:33 AM.
  5. #5
    Hello anh34!

    Glad you could figure out the issue! Sometimes just by writing the test case, by simplifying the whole scenario, we end up finding the issue much easier than trying to debug the whole production project. Seems this was the case.

    Thank you for sharing the solution that worked for you, this might be useful for other people with the same issue in the future.
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. this.Store in Controller compiler error
    By elector in forum 2.x Help
    Replies: 1
    Last Post: Jul 06, 2014, 10:56 AM
  2. How to bind Gridpanel(store) with datatable from controller
    By sunshineenterprises in forum 2.x Help
    Replies: 1
    Last Post: Jul 03, 2014, 8:37 AM
  3. Replies: 2
    Last Post: Nov 13, 2013, 5:24 PM
  4. How to reload store data using mvc controller?
    By FlavioSilveira in forum 2.x Help
    Replies: 1
    Last Post: Feb 22, 2013, 4:22 AM
  5. Replies: 17
    Last Post: Dec 17, 2012, 11:58 AM

Posting Permissions