gpt4 book ai didi

asp.net-mvc - 在不提交值的情况下将值从 Kendo DDL 传递到 ActionLink/ActionImage

转载 作者:行者123 更新时间:2023-12-02 01:58:41 25 4
gpt4 key购买 nike

VS'12 KendoUI InternetApplication 模板 C# asp.net EF 代码优先

我有 2 个下拉列表页面,其中 1 个页面使用 DropDownList 将值发布到 ModelView,另一个只是按 ID 返回。

问题

基本上我想在 View 中保留一个用户可以从中选择的 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");
});
})
)

Action 链接

@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 正在工作,我只是无法传递值....)

UPDATES Model

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; }
}

Controller *A JsonResult GET Method and Post Request

    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 的值 w/o 刷新页面)同样,如果我将 Model.(w/e the data is) 绑定(bind)到 action链接 他们给了我一个null reference

最佳答案

您可以为此使用kendo 模板引用:Kendo DropDownList / Customizing templates

@(Html.Kendo().DropDownList()
.Name("customers")
.HtmlAttributes(new { style = "width: 400px" })
.DataTextField("ContactName")
.DataValueField("CustomerID")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetCustomers", "Home");
});
})
.Height(300)
.Template("<img src=\"" + Url.Content("~/Content/web/Customers/") + "${data.CustomerID}.jpg\" alt=\"${data.CustomerID}\" />" +
"<dl>" +
"<dt>Contact:</dt><dd>${ data.ContactName }</dd>" +
"<dt>Company:</dt><dd>${ data.CompanyName }</dd>" +
"</dl>")
)

更新

您得到的是空值,因为您还没有将 Name 分配给您的 kendo 控件。如果不这样做,控件值将不会绑定(bind)到您的模型。

@(Html.Kendo().DropDownListFor(m=>m.Prospects)
.Name("Prospects") // assign appropriate name
.HtmlAttributes(new { style = "width:300px"}) //, id = "clients"})
.OptionLabel("Select Prospect...")
.DataTextField("ProspectName")
.DataValueField("ProspectID")
.DataSource(source => {
source.Read(read => {
read.Action("GetCascadeProspects", "AddCCCTRST");
});
})
)

关于asp.net-mvc - 在不提交值的情况下将值从 Kendo DDL 传递到 ActionLink/ActionImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18495703/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com