csharp 更新
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 更新相关的知识,希望对你有一定的参考价值。
public async Task<Dictionary<string, object>> UpdatePlanAsync(Plan plan)
{
await _planRepository.UpdateAsync(plan);
return new Dictionary<string, object>
{
{ "success", true },
{ "text", $"{plan.Id} no'lu plan başarıyla güncellendi." }
};
}
@model IEnumerable<PlanViewModel>
@{
var areaName = ViewContext.RouteData.DataTokens["area"];
var controllerName = ViewContext.RouteData.Values["controller"].ToString();
var actionName = ViewContext.RouteData.Values["action"].ToString();
var updateUrl = Url.Action("UpdatePlan", @controllerName, new { area = (string)@areaName });
}
@section PageScriptContent {
<script>
function updatePlan(planId) {
openAjaxPopUp("@updateUrl/" + planId);
}
function ajaxPopUpSucceed(xhr) {
var success = xhr.result.success;
var msgTxt = xhr.result.text;
if (success) { toastr.success(msgTxt, 'İşlem Başarılı'); }
else { toastr.error(msgTxt, 'İşlem Başarısız'); }
grid.ajax.reload(function (json) {
if (json.recordsTotal === 0) {
$("div.step-thin #step4").removeClass("done");
}
});
}
</script>
@Html.RenderScripts() @*for rendering scripts from partial views and editor templates *@
}
[Route("~/Products/Product/UpdatePlan/{productId?}/{planId:int?}")]
[HttpPost]
[ValidateAntiForgeryToken]
[HandleException]
public async Task<ActionResult> UpdatePlan(PlanViewModel vModel)/*, string productId = null, int PlanId = 0*/
{
if (vModel.ProductId != null && vModel.Id > 0)
{
/* adjustments */
vModel.Code = vModel.Code.ToUpper();
/* update Plan as saved */
var plan = await _productManager.GetPlanFirstOrDefault(vModel.Id);
Mapper.Map(vModel, plan);
var success = await _productManager.UpdatePlanAsync(plan);
/* prep operation message */
var msg = success ? "kodlu plan başarıyla güncellendi." : "kodlu plan onaylı olduğu için güncellenemez.";
msg = $"{vModel.Id} " + msg;
/* done - return response */
var resultDict = new Dictionary<string, object>
{
{ "success", true },
{ "text", msg },
{ "id", vModel.Id.ToString() }
};
return Json(resultDict);
}
return RedirectToAction("Index");
}
以上是关于csharp 更新的主要内容,如果未能解决你的问题,请参考以下文章
csharp 更新数据库
csharp 更新
csharp 对我们来说更新
csharp 通过Automapper创建/更新
csharp 对于具有多个更新的循环。
csharp 对于具有多个更新的循环。