[英]Load partial view with parameters
I'm trying to load a partial view with Id parameters inside "Bootstrap Model" 我正在尝试在“ Bootstrap模型”中加载带有Id参数的局部视图
I can't pass the parameters to the controller 我无法将参数传递给控制器
Something like this: 像这样:
<td>
<button class="btnShowModal btn btn-primary btnWhiteSpace " type="button">
Details
<i class="fas fa-info-circle" aria-hidden="true"></i>
</button>
</td>
<div class="modal fade" tabindex="-1" id="loginModal"
data-keyboard="false" data-backdrop="static">
<div class="modal-dialog modal-sm ">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
<i class="fas fa-window-close"></i>
</button>
<h4 class="modal-title"> Title</h4>
</div>
<div class="modal-body ">
<partial name=("bid", "details" asp-route-id="item.QuettaReqId" ) />
</div>
</div>
</div>
</div>
The error I'm getting is: 我得到的错误是:
InvalidOperationException: The partial view '(' was not found. The following locations were searched:
InvalidOperationException:未找到部分视图'('。搜索了以下位置:
Views/Mail/(.cshtml查看/邮件/(CSHTML
/Views/Shared/(.cshtml/Views/Shared/(.cshtml
/Pages/Shared/(.cshtml/Pages/Shared/(.cshtml
It look like routing but I think that the parameter is set also not being pass as should. 看起来像路由,但我认为该参数的设置也未如预期那样通过。
Try this: 尝试这个:
@{ Html.RenderAction("YourActionName", "ControllerName", new { parameterName = parameterValue });}
So in case of you as follows: 因此,在您的情况下如下所示:
<div class="modal-body ">
@{ Html.RenderAction("details", "bid", new { id= item.QuettaReqId});}
</div>
Now if you want a ASP.NET Core specific solution then you can use View Components which is much more faster than Partial View. 现在,如果您需要特定于ASP.NET Core的解决方案,则可以使用比Partial View快得多的View Components 。
For passing item.QuettaReqId
from Main view to partial view, you need to specify the right Partial View Name and model. 为了将
item.QuettaReqId
从主视图传递到局部视图,您需要指定正确的局部视图名称和模型。
<div>
<partial name="_Details" model="10"/>
@await Html.PartialAsync("_Details", 5)
</div>
For _Details
, you need to define @model
to accept the parameter. 对于
_Details
,您需要定义@model
来接受参数。
@model int
This is Detail View with Id @Model
Note , _Details
is the Partial View Name. 注意 ,
_Details
是部分视图名称。
For more information about model
, check model 有关
model
更多信息,请检查模型
The error you are getting because asp.net engine is unable to find the view 由于asp.net引擎找不到视图而导致的错误
You ma replace it with 你可以换成
@Url.Action("YourActionMethod", "Controller", new { param = "1", param2= "2" })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.