Can anyone help me on how to use UniDynArray on ASP.net MVC3 (MS Visual Studio 2010) View Page?
I managed to add reference (U2.Data.Client) to the project and I'm able to use it in the Controller, but not in View page.
The reason to utilize the UniDynArray is that, I would like to pass a dynamic array from Controller to View and back to controller. This way I will not have to set every field to VIEWDATA in order to be use in View.
I would like to explain how to pass UniDynArray to MVC View from Controller the following ways:
In this post , I will answer MVVM Pattern (Raw UniDynArray). Later I will cover rest.
Create ASP.NET MVC3 Project
Create a Model
Add a controller
Create a View
Open ‘CustomerViewModel.cs’ file and paste the following code
namespace Test_MvcApplication.Models {
public class CustomerViewModel
{
public Customer MyCustomer { get; set; }
public CustomerViewModel(Customer pCustomer)
{
MyCustomer = pCustomer;
}
}
public class Customer
{
private UniDynArray myVar;
public UniDynArray MyUniDynArray
{
get
{
U2ConnectionStringBuilder conn_str = new U2ConnectionStringBuilder();
conn_str.UserID = "user";
conn_str.Password = "pass";
conn_str.Server = "localhost";
conn_str.Database = "HS.SALES";
conn_str.ServerType = "UNIVERSE";
conn_str.AccessMode = "Native"; // FOR UO
conn_str.RpcServiceType = "uvcs"; // FOR UO
conn_str.Pooling = false;
string s = conn_str.ToString();
U2Connection con = new U2Connection();
con.ConnectionString = s;
con.Open();
Console.WriteLine("Connected.........................");
// get RECID
UniSession us1 = con.UniSession;
UniSelectList sl = us1.CreateUniSelectList(2);
// Select UniFile
UniFile fl = us1.CreateUniFile("CUSTOMER");
fl.RecordID = "2";
myVar = fl.Read();
return myVar;
}
set
{
myVar = value;
}
}
}
}
Open ‘MyUniDynArrayController.cs’ and paste the following code. As you notice that you are passing object to view and that object has UniDynArray
namespace Test_MvcApplication.Controllers { public class MyUniDynArrayController : Controller { // // GET: /MyUniDynArray/
public ActionResult Index()
{
Customer c = new Customer();
UniDynArray r = c.MyUniDynArray;
var l = new CustomerViewModel(c);
return View(l);
}
}
}
Open ‘MyUniDynArray\ Index.cshtml’ and paste the following code. @Model contains ViewModel object (UniDynArray)
@{ ViewBag.Title = "Index"; }
Open ‘Shared\Layout.cshtml’ file and add the following line
<nav>
<ul id="menu">
<li>@Html.ActionLink("MyUniDynArray", "Index", "MyUniDynArray")</li>
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
</ul>
</nav>
Run the application and press ‘MyUniDynArray’. You will see UniDynArray in View. I am not sure how are you going to bind UniDynArray with HTML5/Razor Controls. That’s why I sugest you to flatten UniDynArray.
Typed UniDynArray in MVC View