使用RenderPartial从URL传递值到另一个视图

时间:2018-10-08 05:18:37

标签: c# .net asp.net-mvc asp.net-mvc-partialview

我有一个使用@ Html.RenderPartial的视图,用于显示另一个视图上存在的某些数据。

我想将URL中存在的ID发送到RenderPartial中,以便可以在其他页面上使用。

以下是我的 JobView.cshtml 代码,该代码使用 @ Html.RenderPartial

@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

我想传递 PostedJobId ,该链接显示在单击 Download CV (下载简历)选项时显示在URL中。

该怎么做?

2 个答案:

答案 0 :(得分:1)

您必须在部分视图中使用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" })

答案 1 :(得分:0)

您可以在代码中添加以下内容:

@Html.ActionLink("Download CV", "DownloadResume", "PostedJob", new { ResumeId = item.NurseResumeList[0].ResumeId , PostedJobId = Request.QueryString["PostedJobId"]}, new { @class = "btnViewJobDetails" })