[HttpPost]
public IHttpActionResult Post([FromBody]Stock stock)
public class Stock
{
public int DealerId { get; set; }
public int StockId { get; set; }
public long Kms { get; set; }
public DateTime MfgYear { get; set; }
}
示例JSON请求:
{
"stock":
{
"DealerId ":234,
"StockId ":123,
"Kms":12324,
"versionId":987,
"MfgYear":2010,
}
}
我需要更改c#Stock类变量名,即从Kms到Kilometer,MfgYear到ManufacturingYear等。
当我将邮递员的数据发布到我的Stock api时,我需要在c#中使用与我在json中相同的参数。有什么方法可以改变这种映射,这样我就能将json Kms映射到C#公里吗?
答案 0 :(得分:2)
只需使用../bower_components/paper-item/paper-item-body.html"
../bower_components/paper-item/paper-icon-item.html"
../bower_components/iron-icons/iron-icons.html"
:
@model Portal.Models.ViewModel.CreateApplicationViewModel
@{
ViewBag.Title = "Step 4/5";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@using System.Linq
<h4>Case Data Details</h4>
@using (Html.BeginForm("Step4", "CreateApplication", FormMethod.Post, new { @class = "col-sm-12" }))
{
int index = 0;
foreach (var group in Model.Step4.DataDetails.GroupBy(item => item.GroupDesc))
{
<div class="panel panel-primary">
<div class="panel-heading">@Html.Encode(group.Key)</div>
<div class="panel-body">
@for (var i = 0; i < group.Count(); i++)
{
<div class="form-group">
<div class="row">
<div class="col-xs-6">
<label class="form-label">@Model.Step4.DataDetails[i].DetailDesc</label>
</div>
<div class="col-xs-6">
@Html.TextBoxFor(val => val.Step4.DataDetails[index].TextValue)
@Html.HiddenFor(val => val.Step4.DataDetails[index].GroupCode)
</div>
</div>
</div>
index++;
}
</div>
</div>
}
<div class="col-sm-12">
<div class="row">
@Html.ActionLink("Cancel", "Welcome", "Home", null, new { @class = "btn btn-default" })
<button class="btn btn-default" onclick="history.go(-1);">Previous</button>
<button type="submit" class="btn btn-default">Next</button>
</div>
</div>
}