首页 > 解决方案 > 使用 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&nbsp;@item.FirstName&nbsp;@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,&nbsp;@item.AddressLine2&nbsp;@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 。

怎么做?

标签: c#.netasp.net-mvcasp.net-mvc-partialview

解决方案


您必须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" })

推荐阅读