2014-02-22 76 views
1

我創建了一個局部視圖,我將這個局部視圖用於另一個視圖,它從_layout繼承m代碼是真實的並且沒有錯誤,但是當我單擊提交時顯示此消息:(無法找到該資源)。我無法追查這個錯誤。請幫幫我 。感謝 這是我news.Cshtml:爲什麼我的部分視圖不能正常工作?

@model MPortal.Models.WebSite_OpinionDB 
@{ 
    Layout = "~/Views/Shared/_Layout.cshtml"; 
} 
@section Body{ 
     @Html.Partial("CreateOpinion") 
     @Html.Action("CreateOpinion", "User") 
} 

這是我_Layout.cshtml:

<html> 
<head> 
    <meta charset="utf-8" /> 
    <meta name="viewport" content="width=device-width" /> 
    <title>@ViewBag.Title</title> 
    <link href="~/Theme/css/bootstrap.css" rel="stylesheet"> 
    <link href="~/Content/CssFramework.css" rel="stylesheet" /> 
    @RenderSection("CSS", required: false) 
</head> 
<body> 
    @RenderSection("Body", required: false) 
    <script src="~/Scripts/jquery-1.7.1.min.js"></script> 
    <script src="~/Scripts/modernizr-2.5.3.js"></script> 
    <script src="~/Theme/js/bootstrap.js"></script> 
    @RenderSection("scripts", required: false) 
</body> 
</html> 

這是我Partialview:(CreateOpinion.cshtml)

@model MPortal.Models.WebSite_OpinionDB 
@section Body{ 
    <div class="" style="float: right; width: 75%"> 
     @Html.Raw(Session["Right"]) 
     @using (Html.BeginForm()) 
     { 
      <div class="rateit" style="float: right; width: 25%"> 
       <input type="text" maxlength="100" value="name" class="form-control" name="Values" id="NameFamily" /> 
       <br /> 
       <input type="text" maxlength="100" value="email" class="form-control" name="Values" id="Email" /> 
       <br /> 
       @Html.TextAreaFor(x => x.OpinionText, new { @class = "form-control", @placeholder = "opinion" }) 
       <br /> 
       <button class="btn btn-primary" type="submit">submit</button> 
      </div> 
     } 
     <div class="" style="width: 20%; height: 625px; border: 1px solid black; float: left"> 
      @Html.Raw(Session["Left"]) 
     </div> 
    </div> 
    <div class="" style="float: right; width: 75%"> 
     @if (ViewData["Success"] != null) 
     { 
      <div class="alert alert-success alert-dismissable"> 
       <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button> 
       @(ViewData["Success"] != null ? ViewData["Success"].ToString() : "") 
      </div> 
     } 
     @if (ViewData["UnSuccess"] != null) 
     { 
      <div class="alert alert-danger bs-alert-old-docs"> 
       <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button> 
       @(ViewData["UnSuccess"] != null ? ViewData["UnSuccess"].ToString() : "") 
      </div> 
     } 
    </div> 
} 

和這是我的局部視角行動:

 [ChildActionOnly] 
     public ActionResult CreateOpinion(MPortal.Models.WebSite_OpinionDB saveop, FormCollection frm) 
     { 
      if (!string.IsNullOrEmpty(frm["Values"])) 
      { 
       int mtID = (int)MPortal_CL.Globals.GetParam("MetaDataID", 0); 
       MPortal.Models.WebSite_OpinionDB op = new MPortal.Models.WebSite_OpinionDB(); 
       String[] texts = frm["Values"].Split(','); 
..... 
....... 
} 

回答

1

刪除屬性[ChildActionOnly]如果這不起作用,請使用超載版本

@using (Html.BeginForm("CreateOpinion","ControllerName")) 
+0

非常感謝。我刪除[ChildActionOnly]並添加(「CreateOpinion」,「ControllerName」)到BeginForm,它的工作。 –

+0

@awesome爲什麼取消ChildActionOnly使它工作?它有什麼問題?出於好奇心問這個問題! –

+0

http://stackoverflow.com/questions/10253769/using-childactiononly-in-mvc –