A.A
A.A

Reputation: 1148

Why does my partial view not working?

I created a partial view and I use this partial to another view that it inherit from a _layout m code is true and doesn't have a bug, but when I click on submit it shows this message : (The resource cannot be found). I can't trace this error . please help me . thanks This is my news.Cshtml:

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

And this is my _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>

And this is my 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>
}

and this is my action of partial view :

     [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(',');
.....
.......
}

Upvotes: 1

Views: 171

Answers (1)

Ilya Sulimanov
Ilya Sulimanov

Reputation: 7836

Remove attribute [ChildActionOnly] and if this does not work please use the overloaded version

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

Upvotes: 1

Related Questions