2012-09-24 87 views
0

我有2個視圖。查看1包含HTML表格和每一行包含一個鏈接到視圖2Http Post方法發射兩次

這是我的廠景

<tr> 
    <td> 
     <a href="@Url.Action("AssignStudent", "Session", new { slotId = item.TimeSlotId, roomId = item.RoomId, roomName = item.RoomName, starttime = dt })">Assign Session </a> 
    </td> 
<tr/> 

在點擊這個時候,就會觸發assignstudent方法在會話控制器

[HttpPost] 
[AllowAnonymous] 
public ActionResult AssignStudent(SessionDashboardViewModel dashboardModel) 
{ 
    dashboardModel.SessionId = Convert.ToInt32(Request.Form["SessionId"]); 
    dashboardModel.RoomId = Convert.ToInt32(Request.Form["hdnRoomId"]); 
    dashboardModel.TimeSlotId= Convert.ToInt32(Request.Form["hdnSlotId"]);  
    SaveMethod(); //save working fine 
    dashboardModel.SessionId = result; 
    ModelState.Clear(); 
    dashboardModel = InitViewData(dashboardModel); 
    return View("SessionDashboard",dashboardModel);// call to source page 
} 

問題出現後,數據保存我已決定調用源頁面,但它從那裏填充源頁面它再次擊中此AssignStudent方法(我不知道爲什麼),並嘗試再次保存數據導致錯誤。

請幫忙。

感謝

回答

0

而不是代碼的最後一行的

return RedirectToAction("SessionDashboard", dashboardModel);