I would like to pass the variables to the other Controllers TableName, I'm trying to ViewBag.Variable but do send the null.
if you can pass these parameters from one controller to another thank you very much in advance for the help
public class HomeController : Controller
{
public ActionResult Index()
{
string NombreVariable = "TablaUsuario";
ViewBag.Variable = NombreVariable;
return View();
}
[ValidateInput(false)]
public ActionResult GridViewPartial()
{
var entity = (IEnumerable)db.GetType()
.GetProperty(ViewBag.Variable)
.GetValue(db, null);
var model = entity.Cast<object>();
return PartialView("_GridViewPartial", model);
}
[HttpPost, ValidateInput(false)]
public ActionResult GridViewPartialAddNew()
{
var entity = (dynamic)db.GetType()
.GetProperty(ViewBag.Variable)
.GetValue(db, null);
var model = entity;
if (ModelState.IsValid)
{
try
{
Model.TableUsuario tb = new Model.TableUsuario();
int contador=tb.GetType().GetProperties().Count();
//Coleccion[] cual = new Coleccion[contador];
int contadores = 0;
string[] valores = new string[contador];
foreach( var i in tb.GetType().GetProperties())
{
valores[contadores] = "'" + Convert.ToString(GridViewExtension.GetEditValue<dynamic>(i.Name)) + "' AS " + i.Name ;
contadores += 1;
}
db.Database.ExecuteSqlCommand("insert into TableUsuario SELECT " + string.Join(",",valores));
db.SaveChanges();
}
catch (Exception e)
{
ViewData["EditError"] = e.Message;
}
}
else
ViewData["EditError"] = "Please, correct all errors.";
return PartialView("_GridViewPartial", model);
}