部分视图无法正确呈现。 [英] Partial view is not rendering properly.

查看:80
本文介绍了部分视图无法正确呈现。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我是MVC新手。

当我们选择第一个时,我有两个下拉菜单我们需要更新第二个。

以下是我的观点

@model HostingManager.Models.ContractManager

@ {

ViewBag.Title =CustomCreate;

}



I''m new to MVC.
I have two drop-downs when we are selecting the first one we need to update the second one.
Below is my view
@model HostingManager.Models.ContractManager
@{
ViewBag.Title = "CustomCreate";
}



@ Html.Partial(_ GroupDDL,型号)


@Html.Partial("_GroupDDL" , Model)









@ Html.Partial(SelectClient,Model)


@Html.Partial("SelectClient", Model)









@ Html.Partial(SelectContract ,型号)


@Html.Partial("SelectContract", Model)





以下是第一个下拉列表(部分视图:_GroupDDL)

@model HostingManager.Models.ContractManager



@using(Ajax.BeginForm(SelectClient,Contracts,new AjaxOptions { UpdateTargetId =IClients}))

{

@ Html.DropDownListFor(

m => m.SelectedGroupId,

new SelectList(Model.IGroups,id,name),

string.Empty



}

< script type =text / javascript>

$(''#SelectedGroupId'')。change(function(){

$(本)。家长(形式)提交();

});

将/脚本>



以下是第二次下拉(部分查看:SelectClient)

@model HostingManager.Models.ContractManager



@if(Model.IClients!= null&& Model.IClients.Count()> 0)

{

使用(Ajax.BeginForm(SelectContracts,Contracts,新的AjaxOptions {UpdateTargetId =IContracts}))

{

@ Html.HiddenFor(m => m.SelectedGroupId)

@ Html.DropDownListFor(

m => m.SelectedClientId,

new SelectList (Model.IClients,id,cname),

string.Empty



}

}



< script type =text / javascript>

$(''#SelectedClientId'')。change( function(){

$(this).parents(''form'')。submit();

});

< ; / script>



以下是我的续滚动

public ActionResult CustomCreate()

{

ContractManager CM = new ContractManager();

CM.IGroups = db.groups.ToList();

返回查看(CM);

}



[HttpPost]

public ActionResult SelectClient(int? SelectedGroupId)

{

ContractManager CM = new ContractManager();

CM.IClients = new List< clients>();

if(SelectedGroupId.HasValue)

{

CM.IClients = db.client.ToList();

}

返回PartialView(SelectClient,CM);

}

现在问题:

在调试模式下,当我选择第一个DDL ..控件来到第二个DDL时,值是第二个DDL没有出现在View.I意味着在UI上我们看不到第二个DDL 。



按照我的代码调用Controller的SelectClient但我的主视图没有使用更新的局部视图进行更新。



任何人都可以告诉问题在哪里..

我已经在我的布局中添加了ajax脚本并在web.config中启用了

我'将过滤第二个DDL the Once如果我能克服这一点。



先谢谢



Below is first Drop-down(Partial View:_GroupDDL)
@model HostingManager.Models.ContractManager

@using (Ajax.BeginForm("SelectClient", "Contracts", new AjaxOptions { UpdateTargetId = "IClients" }))
{
@Html.DropDownListFor(
m => m.SelectedGroupId,
new SelectList(Model.IGroups, "id", "name"),
string.Empty
)
}
<script type="text/javascript">
$(''#SelectedGroupId'').change(function () {
$(this).parents(''form'').submit();
});
</script>

Below is Second Drop-down(Partial View : SelectClient)
@model HostingManager.Models.ContractManager

@if (Model.IClients != null && Model.IClients.Count() > 0)
{
using (Ajax.BeginForm("SelectContracts", "Contracts", new AjaxOptions { UpdateTargetId = "IContracts" }))
{
@Html.HiddenFor(m => m.SelectedGroupId)
@Html.DropDownListFor(
m => m.SelectedClientId,
new SelectList(Model.IClients, "id", "cname"),
string.Empty
)
}
}

<script type="text/javascript">
$(''#SelectedClientId'').change(function () {
$(this).parents(''form'').submit();
});
</script>

Below is my Controller action
public ActionResult CustomCreate()
{
ContractManager CM = new ContractManager();
CM.IGroups = db.groups.ToList();
return View(CM);
}

[HttpPost]
public ActionResult SelectClient(int? SelectedGroupId)
{
ContractManager CM = new ContractManager();
CM.IClients = new List<clients>();
if (SelectedGroupId.HasValue)
{
CM.IClients = db.client.ToList();
}
return PartialView("SelectClient", CM);
}
Now The problem:
In Debugging Mode when I''m selecting the first DDL..Control is coming to second DDL with the values but the Second DDL is not appearing on the View.I mean on UI we can''t see the Second DDL.

As per My Code It is calling the SelectClient of Controller but my Main View is not updating with the updated partial view.

Can anybody plz tell where the problem is..
I already added ajax script in my Layout and also enabled in web.config
I''ll filter the Second DDL the Once if I can overcome this.

Thanks in Advance

推荐答案

(''#SelectedGroupId '')。change(function(){
(''#SelectedGroupId'').change(function () {


(this).parents(''form'')。submit();

});

< / script>



以下是第二次下拉(部分查看:SelectClient)

@model HostingManager.Models.ContractManager



@if(Model.IClients!= null&& Model.IClients.Count()> 0)

{

使用(Ajax.BeginForm(SelectContracts,Contracts,新的AjaxOptions {UpdateTargetId =IContracts}))

{

@ Html.HiddenFor(m => m.SelectedGroupId)

@ Html.DropDownListFor(

m => m.SelectedClientId,

new SelectList (Model.IClients,id,cname),

string.Empty



}

}



< script type =text / javascript>
(this).parents(''form'').submit();
});
</script>

Below is Second Drop-down(Partial View : SelectClient)
@model HostingManager.Models.ContractManager

@if (Model.IClients != null && Model.IClients.Count() > 0)
{
using (Ajax.BeginForm("SelectContracts", "Contracts", new AjaxOptions { UpdateTargetId = "IContracts" }))
{
@Html.HiddenFor(m => m.SelectedGroupId)
@Html.DropDownListFor(
m => m.SelectedClientId,
new SelectList(Model.IClients, "id", "cname"),
string.Empty
)
}
}

<script type="text/javascript">


(''#SelectedClientId '')。change(function(){
(''#SelectedClientId'').change(function () {


这篇关于部分视图无法正确呈现。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆