我有一个根据特定 ID 显示信息的视图。
我的控制器是:
public ActionResult ModifyWorkout(string WorkoutId, bool? Status)
{
Guid pkWorkoutId = new Guid(WorkoutId);
BLLWorkouts _objBLLWorkouts = new BLLWorkouts();
var WorkoutRow = _objBLLWorkouts.GetOneWorkout(pkWorkoutId);
WorkoutModel PageModel = new WorkoutModel
{
pkWorkoutId = WorkoutRow.pkWorkoutId,
WorkoutName = WorkoutRow.WorkoutName,
WorkoutNote = WorkoutRow.WorkoutNote,
Sessions = WorkoutRow.Sessions,
CmpFlag = WorkoutRow.CmpFlag,
tblWorkoutSessions = WorkoutRow.tblWorkoutSessions
};
ViewBag.UpdateStatus = Status;
return View(PageModel);
}
我总是传递一个查询字符串作为锻炼 id 来获取一条记录。但是,当我更新该记录时,它会发布到另一个操作:
public ActionResult UpdateWorkout(WorkoutModel model)
{
bool _status = false;
BLLWorkouts _objBLLWorkouts = new BLLWorkouts();
tblWorkout _row = new tblWorkout();
_row.WorkoutName = model.WorkoutName;
_row.WorkoutNote = model.WorkoutNote;
_row.Sessions = model.Sessions;
_row.pkWorkoutId = model.pkWorkoutId;
_row.CmpFlag = model.CmpFlag;
_status = _objBLLWorkouts.UpdateWorkout(_row);
return RedirectToAction("ModifyWorkout", new { WorkoutId = model.pkWorkoutId, Status = _status });
}
现在的问题是,更新我的网址后变成这样:
/ModifyWorkout?WorkoutId=438b6828-1a21-4ad0-9e40-485dda75b1f6&Status=true"
由于&Status=true
在 Url 中,即使在刷新页面后也会显示状态消息。
<div >
@if (ViewBag.UpdateStatus != null)
{
if (ViewBag.UpdateStatus)
{
<span class="successmsgCommon">Workout updated successfully.</span>
}
else
{
<span class="errormsgCommon">Workout was not updated. Please try again.</span>
}
}
</div>
有没有办法解决这个问题?