2017-10-26 17 views
0

Stories 컨트롤러의 UpdateStories 액션에 데이터를 게시해야하는 EDITSTORIES 부분보기가 있지만 그렇지 않습니다. 그것은 심지어 브레이크 포인트에 부딪치지 않습니다.내 버튼이 컨트롤러에서 동작을 호출하지 않는 이유는 무엇입니까?

@using (Html.BeginForm("UpdateStories", "Stories", FormMethod.Post, new{enctype = "multipart/form-data" })) 
{ 
    @Html.AntiForgeryToken() 

    <div class="form-horizontal"> 
     <h4>Stories</h4> 
     <hr /> 
     @Html.ValidationSummary(true, "", new { @class = "text-danger" }) 
     @Html.HiddenFor(model => model.ID) 

     <div class="form-group"> 
      @Html.LabelFor(model => model.Image, htmlAttributes: new { @class = "control-label col-md-2" }) 
      <div class="col-md-10"> 
       @Html.EditorFor(model => model.Image, new { htmlAttributes = new { @class = "form-control" } }) 
       @Html.ValidationMessageFor(model => model.Image, "", new { @class = "text-danger" }) 
      </div> 
     </div> 

     <div class="form-group"> 
      @Html.LabelFor(model => model.Story, htmlAttributes: new { @class = "control-label col-md-2" }) 
      <div class="col-md-10"> 
       @Html.EditorFor(model => model.Story, new { htmlAttributes = new { @class = "form-control" } }) 
       @Html.ValidationMessageFor(model => model.Story, "", new { @class = "text-danger" }) 
      </div> 
     </div> 


     <div class="form-group"> 
      <div class="col-md-offset-2 col-md-10"> 
       <input type="submit" value="Update" class="btn btn-default" /> 
      </div> 
     </div> 
    </div> 
} 

작업 :

[HttpPost] 
     public ActionResult UpdateStories(Stories st) 
     {  
      ViewBag.Grid= bo.GetAllImages(); 

      if (bo.UpdateImages(st)) 
      { 
       ViewBag.Data = "Updated successfully"; 
      } 
      else 
      { 
       ViewBag.Data = "Update failed"; 
      } 

      ViewBag.Style = "display:none";  
      return View("GetStories", st); 
     } 
    } 

그것은 기본보기입니다 GetStories 내부입니다. 긴 날이었고 아직도 끝나지 않았습니다. 제발 도와주세요.

업데이트 :

경로 :

routes.MapRoute(
       name: "Default", 
       url: "{controller}/{action}/{id}", 
       defaults: new { controller = "Stories", action = "AddStories", id = UrlParameter.Optional } 
      ); 
      routes.MapRoute(
       name: "ShowStories", 
       url: "{controller}/{action}/{id}", 
       defaults: new { controller = "Stories", action = "ShowStories", id = UrlParameter.Optional } 
      ); 

업데이트 :

보기 : GetStories

@model HimHer.Models.Stories 

@{ 
    ViewBag.Title = "Index"; 
    Layout = "~/Views/Shared/_Layout.cshtml"; 
} 

@using (@Html.BeginForm("GetStories", "Stories", FormMethod.Get)) 
{ 
     @Html.AntiForgeryToken() 

    <div style="@ViewBag.Style"> 
     @{ 
      Html.RenderPartial("EditStories", Model); 
     } 


    </div> 

    <hr /> 
    var listData = (List<HimHer.Models.Stories>)ViewBag.Grid; 

    WebGrid wgImages = new WebGrid(listData, rowsPerPage: 20); 
    @wgImages.GetHtml(tableStyle: "table table-condensed table-bordered table-striped table-responsive", 
columns: wgImages.Columns(
         wgImages.Column 
         (columnName: "Image", header: "Image"), 
         wgImages.Column 
         (columnName: "Story", header: "Story"), 
         wgImages.Column 
         (columnName: "Image", header: "Download", format: (testItem) => Html.ActionLink("Download", "DownloadStories", new { filename = testItem.Image })), 
         wgImages.Column 
             (header: "Edit", format: (testitem) => Html.ActionLink("Edit", "EditStories", new { ID = testitem.ID, Story = testitem.Story, Image = testitem.Image, HiddenID = 1 })) 
        ) 
); 



} 

<h2>Index</h2> 
+0

양식 게시 응답의 상태 코드는 무엇입니까? – Jasen

+0

질문에 경로가 표시되지 않았습니다. 또는 컨트롤러의 이름. – mason

+0

@mason udpated and contoller is STORIES –

답변

3

당신의 코드가이 개 형태를 생성하고이 중첩됩니다!

<form action="/Stories/GetStories"> 
    <form action="/Stories/UpdateStories"> 
     <input type="submit" /> 
    </form> 
</form> 

중첩 된 양식이 잘못되었습니다. 부분보기에서 내부 양식의 제출 단추를 누르면 외부 양식에 대해 정의 된 조치 메소드로 제출하기 때문입니다.

양식을 중첩하면 안됩니다. 전화 번호 BeginForm 외의 RenderPartial에 대한 통화로 이동합니다.

공유 한 코드를 보면 제출해야 할 양식 데이터가 없으므로 기본보기에서 양식 태그를 가질 필요가 없습니다. 그러니 간단히 제거하십시오.

다른보기가 기본보기에 절대적으로 필요하면 중첩 된 서식 상황을 만들지 않도록하십시오. 동일한보기에서 2 개의 서식을 평행하게 배열 할 수 있습니다.

@using (@Html.BeginForm("GetStories", "Stories", FormMethod.Get)) 
{ 
    <!-- Some form elements needed for this form -->  

} 

@{ Html.RenderPartial("EditStories", Model); }