c# - 使用 RenderPartial 从 URL 传递值到另一个视图
问题描述
我有一个视图,它使用@Html.RenderPartial 来显示另一个视图上存在的一些数据。
我想将 URL 中存在的 ID 发送到 RenderPartial,以便可以在其他页面上使用它。
以下是我使用@Html.RenderPartial的JobView.cshtml代码:
@model NurseOneStop.SC.PostedJob
@{
ViewBag.Title = "JobView";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="row">
<div class="lstCard">
<div class="applied-view">
<p>
<b>Job Salary:</b> @Model.JobSalary
</p>
<p>
<b>Job Desc:</b> @Model.JobDesc
</p>
<p>
<b>Job Summary:</b> @Model.JobSummary
</p>
<p>
<b>Job Application Type:</b> @Model.JobApplicationType
</p>
<p>
<b>CategoryId:</b> @Model.Category
</p>
<p>
<b>Number Of Positions:</b> @Model.NumberOfPositions
</p>
<p>
<b>CreatedOn:</b> @Model.CreatedOn.ToString("MMM dd, yyyy")
</p>
<p>
<b>Skills:</b> @Model.SkillNames
</p>
<p>
<b>Status:</b> @if (Model.Status)
{
<span>Open</span>
}
else
{
<span>Class</span>
}
</p>
</div>
</div>
</div>
<hr />
<div class="row">
<div class="lstCard">
<h2>Applied Nurses List</h2>
@{
Html.RenderPartial("NurseListView", (List<NurseOneStop.SC.NurseProfile>)Model.AppliedNurses, new ViewDataDictionary { { "PostedJobId", Model.PostedJobId } });
}
</div>
</div>
<p class="back-tolist">
@Html.ActionLink("Back to List", "Index")
</p>
下面是我的NurseListView.cshtml代码:
@model IEnumerable<NurseOneStop.SC.NurseProfile>
@foreach (var item in Model)
{
<div class="col-md-4 col-sm-6 col-xs-12">
<span><b style="color:#007976; font-weight:600;">@item.Title @item.FirstName @item.LastName</b></span><br />
<span><b>Profession:</b> @item.Profession</span><br />
<span><b>Mobile:</b> @item.PhoneNumber</span><br />
<span><b>Email:</b> @item.EmailId</span><br />
<span><b>Verified Email:</b> @(item.IsVerifiedEmail ? "Yes" : "No")</span><br />
<span><b>Verified Contact:</b> @(item.IsVerifiedContact ? "Yes" : "No")</span><br />
<span><b>Applied On:</b> @item.CreatedOn.ToString("dd-MMM-yyyy")</span><br />
<span><b>Skills:</b> @item.Skills</span><br />
<span><b>Address:</b> @item.AddressLine1, @item.AddressLine2 @item.ZipCode</span><br />
@*<span>@item.ProfileUrl</span>*@
<span>@item.CurrentPosition</span><br />
<span>@item.Summary</span><br />
<span>@item.PreferredJobLocation</span>
<p class="no-margin" style="text-align:right">
@Html.ActionLink("Download CV", "DownloadResume", "PostedJob", new { ResumeId = item.NurseResumeList[0].ResumeId , PostedJobId = item.PostedJobId}, new { @class = "btnViewJobDetails" })
<a href="@(System.Configuration.ConfigurationManager.AppSettings["Website"]+"/nurse/NurseView?NurseId=" + item.NurseId)" class="btnViewJobDetails">View Profile</a>
@Html.ActionLink("Message", "SendMessage", "Recruiter", new { NurseId = item.NurseId }, new { @class = "btnViewJobDetails" })
</p>
</div>
}
http://localhost:49509/PostedJob/JobView?PostedJobId=100162&returnUrl=%2FPostedJob%2FIndex
我想通过点击下载简历选项时显示在 URL 中的PostedJobId 。
怎么做?
解决方案
您必须HttpContext.Current.Request.QueryString["PostedJobId"]
在局部视图中使用才能从 URL 访问PostedJobId
值。
@Html.ActionLink("Download CV", "DownloadResume", "PostedJob", new { ResumeId = item.NurseResumeList[0].ResumeId , PostedJobId = Request.QueryString["PostedJobId"]}, new { @class = "btnViewJobDetails" })
推荐阅读
- python - 将从文件读取的二进制数据转换为 uint32 数组
- ios - 在哪里可以找到无法在应用程序内部使用的数据的官方列表?
- c - 如何使用 termios.h 配置串行端口以传递原始字节?
- javascript - 如何在 vue 类组件中访问 $bvToast
- swiftui - 嵌套数组中的已发布变量不显示更改
- javascript - 如何用 API 数据替换硬编码的 React.js 数据?
- python - 如何导入重叠命名空间的 Python 包?
- python - 'Column' 对象不能用 Regex 和 Pyspark 调用
- c++ - 如何在 Visual Studio 中实际使用 vcpkg 安装的包?
- rest - Sharepoint REST API(获取站点应用程序文档库数据)