jqueryを使用してこのアクションを呼び出します
public ActionResult Delete(int Id){
Schedule schedule = context.Schedules.FirstOrDefault(s => s.Id == Id);
try{
context.Schedules.Remove(schedule);
context.SaveChanges();
TempData["Message"] = "Succesfully removed schedule.";
return Content(Boolean.TrueString);
}catch(Exception ex){
TempData["Message"] = "Something went wrong";
return Content(Boolean.FalseString);
}
}
私の見解では、マスターからのTempData["Message"]を処理するdivがあります
<div id="messages">
<% if(ViewContext.TempData["Message"] != null { %>
<div class="alert">
<%: ViewContext.TempData["Message"] %>
</div>
<% } %>
</div>
これはまさに私のjqueryがどのように見えるかです。Boolean.TrueString/FalseStringリターンを使用します。私はまだアクションを使ってjqueryを学び始めているので、それが正しい方法かどうかはよくわかりません。
http://ricardocovo.com/2010/09/02/asp-mvc-delete-confirmation-with-ajax-jquery-ui-dialog/
基本的に、私の目標は、エラーを表示したり、間違っていることや手順を完了するために実行する必要のある指示をユーザーに通知したりできるようにすることです。リターンタイプとしてJSONを使用することを考えていましたか?どうやって扱えばいいのかよくわかりません。
任意の推奨事項は非常に高く評価されています。