VS'12 KendoUI InternetApplication Template C# asp.net EF Code First
我有 2 个下拉列表页面 1 个页面使用 DropDownList 将值发布到 ModelView 另一个只是通过 ID 返回。
疑问
基本上,我想使用用户可以选择的 DDL 留在视图中。此 DDL 的左侧有一个 Actionlink,应该能够使用所选参数转到新的 ACtion。但我的模型值始终为空。如何传递这个值?
下拉列表
<label for="Prospects">Prospect:</label>
@(Html.Kendo().DropDownListFor(m=>m.Prospects)
//.Name("clients")
.HtmlAttributes(new { style = "width:300px"}) //, id = "clients"})
.OptionLabel("Select Prospect...")
.DataTextField("ProspectName")
.DataValueField("ProspectID")
.DataSource(source => {
source.Read(read => {
read.Action("GetCascadeProspects", "AddCCCTRST");
});
})
)
行动链接
@Html.ActionImage("ADD", "Prospect", new { id=Model.Prospects.FirstOrDefault() } , "~/Images/Navigation/Add.PNG", "Add")
..., new { id=Model.Prospects.FirstOrDefault() } ,...,...)
// the Model is null here, how can i pass my value to this actionlink / actionimage?
(ActionImage 来自This Post)如果代码需要在这里发布,请告知。(自定义 ActionImage 正在工作我只是无法传递值....)
更新模型
public class ViewModelCCTRST
{
public string Clients { get; set; }
public IEnumerable<dbClient> AvailableClients { get; set; }
public string Prospects { get; set; }
public IEnumerable<dbProspect> AvailableProspects { get; set; }
public string Countys { get; set; }
public IEnumerable<dbCounty> AvailableCounties { get; set; }
public string TownShips { get; set; }
public IEnumerable<dbTownShip> AvailableTownShip { get; set; }
public string Ranges { get; set; }
public IEnumerable<dbRange> AvailableRanges { get; set; }
public string Sections { get; set; }
public IEnumerable<dbSection> AvailableSection { get; set; }
public string Tracts { get; set; }
public IEnumerable<dbTract> AvailableTracts { get; set; }
}
控制器 *A JsonResult GET 方法和 Post 请求
public JsonResult GetCascadeTracts(int sections)
{
var tract = db.Tracts.AsQueryable();
if (0 != sections)
{
tract = tract.Where(o => o.SectionID == sections);
}
return Json(tract.Select(o => new { TractID = o.TractID, TractName = o.TractNumber }), JsonRequestBehavior.AllowGet);
}
[HttpPost]
public ActionResult Index(ViewModelCCTRST model)
{
if (ModelState.IsValid)
{
//string clt = model.Clients;
string pro = model.Prospects;
string cnt = model.Countys;
string twn = model.TownShips;
string rng = model.Ranges;
string sct = model.Sections;
string trt = model.Tracts;
return Content(cnt + twn + rng + sct + trt);
}
else
{
return Content("");
}
}
**正如下面所讨论的,我的方法中确实有值Post
,但我的方法中没有任何值View
(这是我希望能够有值来使用我的不Actionlinks
刷新页面的地方),如果我把Model.(w/e the data is)
进了action links
他们给我一个null reference
。