如何在局部视图中传递两个参数我的视图没有任何控制器我只需要调用局部视图并将两个参数传递给局部视图 [英] How To Pass Two Parameter In Partial View My View Does't Have Any Controller I Just Need To Call Partial View And Pass Two Parameter To That Partial View

查看:68
本文介绍了如何在局部视图中传递两个参数我的视图没有任何控制器我只需要调用局部视图并将两个参数传递给局部视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码调用的部分视图名为PartialPatientHeaderDetails
@ Html.Partial(PartialPatientHeaderDetails,new {@ Model.CaseId,@ havePatientName})

这是PartialPatientHeaderDetails视图的代码
@model int
@ {
int Id = Model;
}
我如何传递参数并在视图中接收该参数现在我有这样的错误< blockquote class = quote > < div class = op > 引用:< / div > 传入的模型项字典的类型为< > f__AnonymousType8`2 [System.Int32,System.String] ',但这本词典需要一个模型System.Int32类型的项目。< / blockquote > p>

解决方案

创建一个类并添加两个属性示例如下所示

  public   class  YourClassName {
public int CaseId { get ; set ;}
public string PatientName { get ; set ;}
}





并调用部分视图,例如

 @ Html.Partial(  PartialPatientHeaderDetails new  YourClassName {C aseId = @ Model.CaseId,PatientName = @havePatientName})





最后在部分视图中更改您的返回模式

 @model YourClassName 
@ {

}
< p> @ Model.CaseId < / p >
< p> @ Model.PatientName < / p >



希望这有帮助


 This code call's the partial view named "PartialPatientHeaderDetails"
     @Html.Partial("PartialPatientHeaderDetails", new {  @Model.CaseId, @havePatientName })

This is the code of PartialPatientHeaderDetails view 
   @model int 
@{
    int Id = Model;
}  
how do i pass parameters and receive that parameters in view now i'm having error like this "<blockquote class="quote"><div class="op">Quote:</div>The model item passed into the dictionary is of type '<>f__AnonymousType8`2[System.Int32,System.String]', but this dictionary requires a model item of type 'System.Int32'.</blockquote>"

解决方案

Create a class and add two properties example like below

public class YourClassName{
public int CaseId{get;set;}
public string PatientName{get;set;}
}



and call your partial view like

@Html.Partial("PartialPatientHeaderDetails", new YourClassName{CaseId=  @Model.CaseId,PatientName= @havePatientName })



finally change your return mode in partial View

 @model YourClassName 
@{
    
}  
<p>@Model.CaseId</p>
<p>@Model.PatientName</p>


Hope this helps


这篇关于如何在局部视图中传递两个参数我的视图没有任何控制器我只需要调用局部视图并将两个参数传递给局部视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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