I'm trying to create s simple ASP.NET MVC 5 (Razor) application.
On start the contoller looks in a specified folder and makes a list of all files in this folder.
This list should be displayed in the igcombo as a dropdown-list.
When the user select a filename in the dropdown-list, the name of the selected file should be send back to the contoller.
So I created a viewmodel to transport the filenames from the controller to the view.
1. How can I bind the filenames to the dropdown-list?
2. How can I submit the selected filename?
All examples, that I found, are simple examples with only a static array in the <script> tag.
If I try this example, I can't use it in the view. When I type "@using Infragistics.Web.Mvc" in the view, VS2013 tells me, that the namespace Infragistics is unknown. But I have a reference to the Infragistics.Web.Mvc.dll assembly, and I can use it in the controller.
I there a best practice example for igcombo data binding and ASP.NET MVC? I found this, but this is not razor, and i can't use "@using Infragistics.Web.Mvc" in the view.
I also found the loadOnDemand. I think, with this option the igcombo can load the data from a dataSource only if it's needed, right? Can I use this with ASP.NET MVC?
Hello Darius,
Thank you for contacting us.
It is possible to send the selected items from the drop down to the view. In fact I have created a sample for you in order to show you how to implement such functionality.
Basically I have a button which is used to trigger the postback, also I store the selected IDs of the items into hidden field from which I will get them on my GetIDs action result method. after that you can use them as you want.
Code snippet:
<script> $(function () { $("#getThemAllBtn").click(function () { var items = $('#combo1').igCombo("selectedItems"); var ids = [items.length];
for (var i = 0; i < items.length; i++) { ids[i] = items[i].data.LocationID; }
$("#selectedItemsIDs").val(ids); }); });</script>
View:
[HttpPost]public ActionResult GetIDs(FormCollection collection){ Factory factory = new Factory(); List<ComboExample.Models.Location> locations = factory.GetLocation(); string[] selectedIDs = collection.Get("selectedItemsIDs").Split(','); // Custom code adding the new or editted elements to the database return View("MultiSelection", locations.First<ComboExample.Models.Location>());}
Have a look at the attached sample.
About the error with the dll's, are you sure that Infragistics.Web.Mvc dll have the same Version as System.Web,Mvc dll. For example, the sample that is attached is using MVC 4, and both references are with Version 4.
I have enabled project NuGetPackage restore so you should add your corresponding Infragistics.Web.Mvc dll and just build the project in order to run it. Also to change the js Scripts.
Looking forward to hearing from you.
Thx!
I can compile your example. But if I start it, I get this:
This means, that the Infragistics.Web.Mvc.dll or a dependency of it couldn't be found.
If I look in the references of your example (.NET 4), I can attach this dlls:
Im my project (.NET 4.5.1) I can attach this:
This is what I have installed:
When I try to use the dll in a view, it looks like this:
But in the controller it seems to be no problem:
I'm really confused ;-)
The project that I've sent you is build with Target framework: .NET 4. You can change it to be 4.5.1. Another solution would be (and the clearest one also) to create a new project and just copy the MultiSelection View, Controller and add the corresponding models (Factory and Location). Also you should keep in mind that the System.Web.MVC dll should be with the version of the framework.
If you have your dll's in the GAC, you can make your project to het them from there, by setting Specific version to false (right click on the reference and press Properties).
Looking forward for your reply.
I created a new project and copied your classes: Download my test project
This is, how it looks like:
I'm curious if this project will run at your computer.
Ok, I figure out, that the dll has to be a local copy.
But now I have an other problem. I try to figure it out untill tomorrow.
If it will not work, I will write it here.
Okay Darius,
Looking forward to it.
I startet a clean project again, linked the Infragistics.Web.Mvc as local copy and corrected the includes of the js-files. And now it works :-)
Thank you for your help.