2012-09-14 2 views
0

만들기 작업으로 새 레코드를 만들려고하면 실패하지만 오류가 없습니다. 나는 그것이 왜 또는 왜 오류가 없는지 정확히 알지 못합니다. 검색 동작을 사용하여 만들기 동작의 일부 필드를 채우고 나머지 정보를 채 웁니다.MVC 컨트롤러가 레코드를 만들지 않습니다

[HttpPost] 
    public ActionResult Create(Incident incident) 
    { 
     if (ModelState.IsValid) 
     { 
      db.Incidents.AddObject(incident); 
      db.SaveChanges(); 
      return RedirectToAction("Index"); 
     } 

     ViewBag.IncidentCreatedBy = new SelectList(db.Creators, "CreatorID", "CreatorName", incident.IncidentCreatedBy); 
     ViewBag.ErrorType = new SelectList(db.Errors, "ErrorID", "ErrorDescription", incident.ErrorType); 
     ViewBag.IncidentID = new SelectList(db.IncidentItems, "IncidentID", "IncidentItem1", incident.IncidentID); 
     ViewBag.IncidentReasonID = new SelectList(db.IncidentReasons, "IncidentReasonID", "ReasonDescription", incident.IncidentReasonID); 
     ViewBag.IncidentResolutionID = new SelectList(db.IncidentResolutions, "IncidentResolutionID", "ResolutionDescription", incident.IncidentResolutionID); 
     ViewBag.InventoryStatus = new SelectList(db.InventoryStatus, "InvStatusID", "InvStatusValue", incident.InventoryStatus); 
     ViewBag.ShipperID = new SelectList(db.ShipperIDs, "ShipperID1", "ShipperName", incident.ShipperID); 
     return View(incident); 
    } 

public ActionResult Search(string searchString) 
    { 
     Incident i = new Incident(); 

     if (!String.IsNullOrEmpty(searchString)) 
     { 
      Tracking result = db1.Trackings.FirstOrDefault(r => r.OrderNum == searchString); 
      if (result == null) 
      { 
       return View(); 
      } 
      else 
      { 
       i.Email = result.Email; 
       i.OriginalShipDate = result.ShipDate; 
       i.Name = result.Name; 
       i.OrderID = result.OrderNum; 
       i.IncidentReasonID = 1; 

       ViewBag.IncidentCreatedBy = new SelectList(db.Creators, "CreatorID", "CreatorName", i.IncidentCreatedBy); 
       ViewBag.ErrorType = new SelectList(db.Errors, "ErrorID", "ErrorDescription", i.ErrorType); 
       ViewBag.IncidentID = new SelectList(db.IncidentItems, "IncidentID", "IncidentItem1", i.IncidentID); 
       ViewBag.IncidentReasonID = new SelectList(db.IncidentReasons, "IncidentReasonID", "ReasonDescription", i.IncidentReasonID); 
       ViewBag.IncidentResolutionID = new SelectList(db.IncidentResolutions, "IncidentResolutionID", "ResolutionDescription", i.IncidentResolutionID); 
       ViewBag.InventoryStatus = new SelectList(db.InventoryStatus, "InvStatusID", "InvStatusValue", i.InventoryStatus); 
       ViewBag.ShipperID = new SelectList(db.ShipperIDs, "ShipperID1", "ShipperName", i.ShipperID); 


       return PartialView("~/Views/Home/Create.cshtml", i); 
      } 
     } 
     else { return View(); } 

    } 

//search view 
<div> 
@Html.ActionLink("Back to List", "Index") 
</div> 
@using (Html.BeginForm("Search", "Home", FormMethod.Post)){  
    <p> Order #: @Html.TextBox("SearchString") <br /> 
    <input type="submit" value="Filter" /></p> 
    } 
@if(IsPost){} 

--create view 
@model RMA_MAID_EASY.Models.Incident 

@{ 
ViewBag.Title = "Create"; 
} 
<script type="text/javascript" ></script> 
<script> 
$(function() { 
    $("#datepicker").datepicker(); 
});  
</script> 




<h2>Create</h2> 

@using (Html.BeginForm()) { 
@Html.ValidationSummary(true) 


<fieldset> 
<legend>Incidents</legend> 
<table> 

    @*<tbody>*@ 
     <tr> 
      <td><div class="editor-label">@Html.LabelFor(model => model.OrderID)</div>  <div class="editor-field">@Html.EditorFor(model => model.OrderID)@Html.ValidationMessageFor(model => model.OrderID)</div></td> 
      <td><div class="editor-label">@Html.LabelFor(model => model.Email)</div><div class="editor-field">@Html.EditorFor(model => model.Email)@Html.ValidationMessageFor(model => model.Email)</div></td> 
      <td><div class="editor-label">@Html.LabelFor(model => model.Name)</div><div class="editor-field">@Html.EditorFor(model => model.Name)@Html.ValidationMessageFor(model => model.Name)</div></td> 
      <td><div class="editor-label">@Html.LabelFor(model => model.OriginalShipDate)</div><div class="editor-field">@Html.EditorFor(model => model.OriginalShipDate)@Html.ValidationMessageFor(model => model.OriginalShipDate)</div></td> 
      <td><div class="editor-label">@Html.LabelFor(model => model.IncidentReasonID, "IncidentReason")</div><div class="editor-field">@Html.DropDownList("IncidentReasonID", String.Empty)@Html.ValidationMessageFor(model => model.IncidentReasonID)</div></td> 

     </tr> 
     <tr> 
      <td><div class="editor-label">@Html.LabelFor(model => model.IncidentResolutionID, "IncidentResolution")</div><div class="editor-field">@Html.DropDownList("IncidentResolutionID", String.Empty)@Html.ValidationMessageFor(model => model.IncidentResolutionID)</div></td> 
      <td><div class="editor-label">@Html.LabelFor(model => model.Notes)</div><div class="editor-field">@Html.EditorFor(model => model.Notes)@Html.ValidationMessageFor(model => model.Notes)</div></td> 
      @*<td><div class="editor-label">@Html.LabelFor(model => model.ReturnTagRequired)</div><div class="editor-field">@Html.EditorFor(model => model.ReturnTagRequired)@Html.ValidationMessageFor(model => model.ReturnTagRequired)</div></td>*@ 
      <td><div class="editor-label">@Html.LabelFor(model => model.ReturnTagRequired)</div><div class="editor-field">@Html.DropDownListFor(x => x.RefundRequired, new SelectList(new Dictionary<string, string> { {"Y", "Yes"}, {"N", "No"} },"key", "value", Model.RefundRequired))</div></td> 
      <td><div class="editor-label">@Html.LabelFor(model => model.DateRetTagGenerated)</div><div class="editor-field">@Html.TextBoxFor(model => model.DateRetTagGenerated, new { id = "datepicker", type = "text" })@Html.ValidationMessageFor(model => model.DateRetTagGenerated)</div></td> 
      @*<td><div class="editor-label">@Html.LabelFor(model => model.RefundRequired)</div><div class="editor-field">@Html.EditorFor(model => model.RefundRequired)@Html.ValidationMessageFor(model => model.RefundRequired)</div></td>*@ 

      <td><div class="editor-label">@Html.LabelFor(model => model.RefundRequired)</div><div class="editor-field">@Html.DropDownListFor(x => x.RefundRequired, new SelectList(new Dictionary<string, string> { {"Y", "Yes"}, {"N", "No"} },"key", "value", Model.RefundRequired)) </div></td> 
     </tr> 
     <tr bgcolor ="#D3D3D3"> 

      <td><div class="editor-label">@Html.LabelFor(model => model.RefundAmount)</div><div class="editor-field">@Html.EditorFor(model => model.RefundAmount)@Html.ValidationMessageFor(model => model.RefundAmount)</div></td> 
      <td><div class="editor-label">@Html.LabelFor(model => model.DateRefundIssued)</div><div class="editor-field">@Html.EditorFor(model => model.DateRefundIssued)@Html.ValidationMessageFor(model => model.DateRefundIssued)</div></td> 
      <td><div class="editor-label">@Html.LabelFor(model => model.ShipperID, "ShipperID1")</div><div class="editor-field">@Html.DropDownList("ShipperID", String.Empty)@Html.ValidationMessageFor(model => model.ShipperID)</div></td> 
      <td><div class="editor-label">@Html.LabelFor(model => model.InventoryItem)</div><div class="editor-field">@Html.EditorFor(model => model.InventoryItem)@Html.ValidationMessageFor(model => model.InventoryItem)</div></td> 
      <td><div class="editor-label">@Html.LabelFor(model => model.InventoryQuantity)</div><div class="editor-field">@Html.EditorFor(model => model.InventoryQuantity)@Html.ValidationMessageFor(model => model.InventoryQuantity)</div></td> 
     </tr> 
     <tr> 

      <td><div class="editor-label">@Html.LabelFor(model => model.eBayCredit)</div><div class="editor-field">@Html.EditorFor(model => model.eBayCredit)@Html.ValidationMessageFor(model => model.eBayCredit)</div></td> 
      <td><div class="editor-label">@Html.LabelFor(model => model.eBayCreditFileDate)</div><div class="editor-field">@Html.EditorFor(model => model.eBayCreditFileDate)@Html.ValidationMessageFor(model => model.eBayCreditFileDate)</div></td> 
      <td><div class="editor-label">@Html.LabelFor(model => model.LostValue)</div><div class="editor-field">@Html.EditorFor(model => model.LostValue)@Html.ValidationMessageFor(model => model.LostValue)</div></td> 
      <td><div class="editor-label">@Html.LabelFor(model => model.IncidentCreatedBy, "Creator")</div><div class="editor-field">@Html.DropDownList("IncidentCreatedBy", String.Empty)@Html.ValidationMessageFor(model => model.IncidentCreatedBy)</div></td> 
      <td><div class="editor-label">@Html.LabelFor(model => model.IncidentReturnDate)</div><div class="editor-field">@Html.EditorFor(model => model.IncidentReturnDate)@Html.ValidationMessageFor(model => model.IncidentReturnDate)</div></td> 
     </tr> 

     <tr bgcolor ="#D3D3D3"> 
      <td><div class="editor-label">@Html.LabelFor(model => model.IncidentResolved)</div><div class="editor-field">@Html.EditorFor(model => model.IncidentResolved)@Html.ValidationMessageFor(model => model.IncidentResolved)</div></td> 
      <td><div class="editor-label">@Html.LabelFor(model => model.IncidentReceived)</div><div class="editor-field">@Html.EditorFor(model => model.IncidentReceived)@Html.ValidationMessageFor(model => model.IncidentReceived)</div></td> 
      <td><div class="editor-label">@Html.LabelFor(model => model.ShippingCost)</div><div class="editor-field">@Html.EditorFor(model => model.ShippingCost)@Html.ValidationMessageFor(model => model.ShippingCost)</div></td> 
      <td><div class="editor-label">@Html.LabelFor(model => model.IncidentCreatedDate)</div><div class="editor-field">@Html.EditorFor(model => model.IncidentCreatedDate)@Html.ValidationMessageFor(model => model.IncidentCreatedDate)</div></td> 
      <td><div class="editor-label">@Html.LabelFor(model => model.RMANumber)</div><div class="editor-field">@Html.EditorFor(model => model.RMANumber)@Html.ValidationMessageFor(model => model.RMANumber)</div></td> 

     </tr> 

     <tr>     
      <td><div class="editor-label">@Html.LabelFor(model => model.RMARequested)</div><div class="editor-field">@Html.EditorFor(model => model.RMARequested)@Html.ValidationMessageFor(model => model.RMARequested)</div></td> 
      <td><div class="editor-label">@Html.LabelFor(model => model.RestockOption)</div><div class="editor-field">@Html.EditorFor(model => model.RestockOption)@Html.ValidationMessageFor(model => model.RestockOption)</div></td> 
      <td><div class="editor-label">@Html.LabelFor(model => model.ReceivedNotes)</div><div class="editor-field">@Html.EditorFor(model => model.ReceivedNotes)@Html.ValidationMessageFor(model => model.ReceivedNotes)</div></td> 
      <td><div class="editor-label">@Html.LabelFor(model => model.InventoryStatus, "InventoryStatu")</div><div class="editor-field">@Html.DropDownList("InventoryStatus", String.Empty)@Html.ValidationMessageFor(model => model.InventoryStatus)</div></td> 
      <td><div class="editor-label">@Html.LabelFor(model => model.ErrorType, "Error")</div><div class="editor-field">@Html.DropDownList("ErrorType", String.Empty)@Html.ValidationMessageFor(model => model.ErrorType)</div></td> 

     </tr> 

     <tr bgcolor ="#D3D3D3"> 
      <td><div class="editor-label">@Html.LabelFor(model => model.ReplacementOption)</div><div class="editor-field">@Html.EditorFor(model => model.ReplacementOption)@Html.ValidationMessageFor(model => model.ReplacementOption)</div></td> 
      <td><div class="editor-label">@Html.LabelFor(model => model.Replacement)</div><div class="editor-field">@Html.EditorFor(model => model.Replacement)@Html.ValidationMessageFor(model => model.Replacement)</div></td> 
      <td><div class="editor-label">@Html.LabelFor(model => model.OurShippingCost)</div><div class="editor-field">@Html.EditorFor(model => model.OurShippingCost)@Html.ValidationMessageFor(model => model.OurShippingCost)</div> 


     </tr> 

    @*</tbody> 
*@</table> 
<p> 
       <input type="submit" value="Create" /> 
       @Html.ActionLink("Back to List", "Index") 
      </p> 

</fieldset> 

}

+0

ModelState.IsValid가 true입니까? –

+2

"실패합니까?" 저장하지 않습니까? 저장을 건너 뛰는가? 사건은 null입니까? 어디로 리디렉션됩니까? –

+0

연결 문자열이 올바른 데이터베이스를 가리키고 있습니까? 실제로 절약 할 수도 있지만 잘못된 데이터베이스를보고있는 경우에는 볼 수 없습니다. 이것은 컨벤션 네이밍을 사용하여 새로운 데이터베이스를 생성하기 때문에 코드 퍼스트를 사용한다면 쉽게 할 수 있습니다. –

답변

0

그 ... 당신이 할 수있는 몇 가지 말을 하드 : - 사용 방화 광 PARAMS는 액션 에 다시 게시되고있는 것을 볼 수 - 당신의 작성 작업을 주위에 몇 중단 점을 설정 올바른 개체/값이 처리되고 있는지 확인합니다.

관련 문제