I have a drop down that needs to trigger a Url.Action with the id value that has been clicked
Currently I have: Model
using System.Collections.Generic;
using System.Data.Entity;
using System.Web.Mvc;
namespace Portal.Models
{
public class CompanyViewModel
{
public int Id { get; set; }
public string CompanyName { get; set; }
public IEnumerable<SelectListItem> CompaniesList { get; set; }
}
public class CompanyViewModelDbContext : DbContext
{
public DbSet<CompanyViewModel> Contacts { get; set; }
}
}
View
@model Portal.Models.CompanyViewModel
@{
ViewBag.Title = "ShowDropdown";
}
@Html.DropDownListFor(m => m.Id, new SelectList(ViewBag.CompanyList as System.Collections.IEnumerable, "CoId","CompanyName"), Url.Action("SelectCompany", "Home", new { partnerCoId = "CoId" }, null))
Controller methods
public PartialViewResult ShowDropdown()
{
var coid = Lt.GetThisUsersCoId();
var model = new CompanyViewModel();
using (var dc = new CompanyViewModelDbContext())
{
var content =
(from cr in db.CompanyRelationship
//This is grabbing all related companies to the logged in user
join c in db.Companies on cr.CoId equals c.CoId
where cr.PartnerCoId == coid
select new
{
cr.CoId,
c.CompanyName
}).Distinct().ToList();
ViewBag.CompanyList = content;
foreach (var item in content)
{
model.Id = item.CoId;
model.CompanyName = item.CompanyName;
}
}
return PartialView(model);
}
public ActionResult SelectCompany(int partnerCoId, string redirect)
{//Bunch of code that I didn't write but just needs to be triggered on click
The drop down should list a bunch of companies based on a global value, after one is select it sets up a relationship.
What I am trying to accomplish: Trigger the ActionResult SelectCompany based on what is chosen from the drop down. Currently it doesn't seem to do anything, is there any good debugging tools I should be using in VS to see what happens when I click the drop down. From my front end it appears as if nothing happens when I select a company.
UPDATE I have gotten the script call into my View but I am having trouble using the @url.Action from within it, I have to pass this:
@Url.Action("SelectCompany", "Home", new {partnerCoId = x})
The value selected from the drop down.