如何从管理端获取数据然后显示在客户端?
how to fetch the data from adminside and then display in client side?
admin端目前有3个职位空缺,我想在客户端carrer页面显示它们
如果管理员端删除所有空缺则显示客户端现在没有空缺
管理员端(使用entity framework):
[HttpGet]
[AllowAnonymous]
public ActionResult DisplayVacancyData()
{
var list = _dbfltEntities.tbl_vacancy.ToList();
return View(list);
}
查看管理员侧视图:
客户端(不使用entity framework)
HomeController.cs
[HttpGet]
public async Task<ActionResult> Career(Vacancy _vacancy)
{
HttpClient client = new HttpClient();
HttpResponseMessage responseMessage = client.GetAsync("https://localhost:44325/Home/DisplayVacancyData").Result;
if (responseMessage.IsSuccessStatusCode)
{
await responseMessage.Content.ReadAsStringAsync();
}
return View();
}
看到响应没问题,但是应该应用哪个逻辑来显示数据
vacancy.cs
public class Vacancy
{
public int vacancyid { get; set; }
public string vacancytitle { get; set; }
public string vacancyposition { get; set; }
public string vacancyexperience { get; set; }
public string vacancyjobdescription { get; set; }
public string vacancyrequiredskil { get; set; }
}
careerpage.cshtml
<style type="text/css">
.actionlink {
font-size: 25px;
color: cornflowerblue;
}
</style>
<div class="container">
<div class="row">
<div class="col-md-6">
<h2 style="margin-top:150px;">Current Job Openings</h2>
</div>
<div class="col-md-4" style="margin-top:155px;">
@Html.ActionLink("Apply for Job", "ApplyForJob", null, new { @class = "actionlink" })
</div>
</div>
<div class="row">
<p> ssss ss sss a sss s of an ss-sssss s ss? s ss with s, ssss s enthusiassm s s? s s aside s s s s s s. s over ssss s s s s s sss below:</p>
</div>
</div>
我正在尝试使用 viewbag 获取数据
HomeController.cs
if (responseMessage.IsSuccessStatusCode)
{
await responseMessage.Content.ReadAsStringAsync();
ViewBag.vacancytitle = _vacancy.vacancytitle; //I am seeing in watch window but it is null
}
访问职业视图页面中的视图包
@ViewBag.vacancytitle
帮助
Return 函数 responseMessage.Content.ReadAsStringAsync() 的值被忽略。
管理员端(使用entity framework),
添加操作 (return json):
[HttpGet]
[AllowAnonymous]
public ActionResult GetVacancyData()
{
var list = _dbfltEntities.tbl_vacancy.ToList();
return new JsonResult(list);
}
HomeController.cs
(客户端 URI“https://.../Home/GetVacancyData”)
[HttpGet]
public async Task<ActionResult> Career()
{
HttpClient client = new HttpClient();
HttpResponseMessage responseMessage = client.GetAsync("https://localhost:44325/Home/GetVacancyData").Result;
if (responseMessage.IsSuccessStatusCode)
{
string result = await responseMessage.Content.ReadAsStringAsync();
List<Vacancy> products = JsonConvert.DeserializeObject<List<Vacancy>>(result);
return View(products);
}
return View();
}
careerpage.cshtml
@foreach (var item in Model)
{
<p>@item.vacancytitle</p>
}
admin端目前有3个职位空缺,我想在客户端carrer页面显示它们 如果管理员端删除所有空缺则显示客户端现在没有空缺
管理员端(使用entity framework):
[HttpGet]
[AllowAnonymous]
public ActionResult DisplayVacancyData()
{
var list = _dbfltEntities.tbl_vacancy.ToList();
return View(list);
}
查看管理员侧视图:
客户端(不使用entity framework)
HomeController.cs
[HttpGet]
public async Task<ActionResult> Career(Vacancy _vacancy)
{
HttpClient client = new HttpClient();
HttpResponseMessage responseMessage = client.GetAsync("https://localhost:44325/Home/DisplayVacancyData").Result;
if (responseMessage.IsSuccessStatusCode)
{
await responseMessage.Content.ReadAsStringAsync();
}
return View();
}
看到响应没问题,但是应该应用哪个逻辑来显示数据
vacancy.cs
public class Vacancy
{
public int vacancyid { get; set; }
public string vacancytitle { get; set; }
public string vacancyposition { get; set; }
public string vacancyexperience { get; set; }
public string vacancyjobdescription { get; set; }
public string vacancyrequiredskil { get; set; }
}
careerpage.cshtml
<style type="text/css">
.actionlink {
font-size: 25px;
color: cornflowerblue;
}
</style>
<div class="container">
<div class="row">
<div class="col-md-6">
<h2 style="margin-top:150px;">Current Job Openings</h2>
</div>
<div class="col-md-4" style="margin-top:155px;">
@Html.ActionLink("Apply for Job", "ApplyForJob", null, new { @class = "actionlink" })
</div>
</div>
<div class="row">
<p> ssss ss sss a sss s of an ss-sssss s ss? s ss with s, ssss s enthusiassm s s? s s aside s s s s s s. s over ssss s s s s s sss below:</p>
</div>
</div>
我正在尝试使用 viewbag 获取数据
HomeController.cs
if (responseMessage.IsSuccessStatusCode)
{
await responseMessage.Content.ReadAsStringAsync();
ViewBag.vacancytitle = _vacancy.vacancytitle; //I am seeing in watch window but it is null
}
访问职业视图页面中的视图包
@ViewBag.vacancytitle
帮助
Return 函数 responseMessage.Content.ReadAsStringAsync() 的值被忽略。
管理员端(使用entity framework), 添加操作 (return json):
[HttpGet]
[AllowAnonymous]
public ActionResult GetVacancyData()
{
var list = _dbfltEntities.tbl_vacancy.ToList();
return new JsonResult(list);
}
HomeController.cs
(客户端 URI“https://.../Home/GetVacancyData”)
[HttpGet]
public async Task<ActionResult> Career()
{
HttpClient client = new HttpClient();
HttpResponseMessage responseMessage = client.GetAsync("https://localhost:44325/Home/GetVacancyData").Result;
if (responseMessage.IsSuccessStatusCode)
{
string result = await responseMessage.Content.ReadAsStringAsync();
List<Vacancy> products = JsonConvert.DeserializeObject<List<Vacancy>>(result);
return View(products);
}
return View();
}
careerpage.cshtml
@foreach (var item in Model)
{
<p>@item.vacancytitle</p>
}