Exception Message:A public action method 'content' was not found on controller 'MDBLandingPage.Controllers.BatchController

Viewed 31

Below is the View File

@model MDBLandingPage.Model.BatchModel

@{
    ViewBag.Title = "ManageBatch";
}
<style>
    label {
        font-weight: 500;
    }
</style>
<h2>ManageBatch</h2>
<hr />
@using (Html.BeginForm())
{
<div class="form-group">
    <div class="col-md-12">
        @Html.HiddenFor(model => model.Id)
        <div class="row">
            <div class="col-md-4">
                <label>Batch Description</label>
                @Html.EditorFor(model => model.BatchName, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.BatchName, "", new { @class = "text-danger" })
            </div>
            <div class="col-md-4">
                <label> Select Board</label>
                @Html.DropDownList("BoardId", null, htmlAttributes: new { @class = "form-control", @name = "BoardId" })
                @Html.ValidationMessageFor(model => model.BoardId, "", new { @class = "text-danger" })
            </div>
            <div class="col-md-4">
                <label>  Select Standard </label>
                @Html.DropDownList("StanderdId", null, htmlAttributes: new { @class = "form-control", @name = "StanderdId" })
                @Html.ValidationMessageFor(model => model.StandardId, "", new { @class = "text-danger" })
            </div>

        </div>

        <div class="row">


            <div class="col-md-4">
                <label>Start Date</label><br />
                <input id="FromDate" name="FromDate" class="form-control" type="date" value="@DateTime.Now.ToString("yyyy-MM-dd")" required />
            </div>
            <div class="col-md-4">
                <label>End Date</label><br />
                <input id="ToDate" type="date" class="form-control" value="@DateTime.Now.AddMonths(3).ToString("yyyy-MM-dd")" name="ToDate" required />
            </div>
            <div class="col-md-4">
                <label>Max Student Capacity</label>
                @Html.EditorFor(model => model.MaxStudent, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.MaxStudent, "", new { @class = "text-danger" })
            </div>
        </div>
        <hr />

        <div class="row">
            <div class="col-md-3">
                <label> Select Subjects</label>
                @Html.DropDownList("SubjectId", null, htmlAttributes: new { @class = "form-control" })
            </div>
            <div class="col-md-3">
                <label>  Select Teacher </label>
                @Html.DropDownList("TeacherId", null, htmlAttributes: new { @class = "form-control" })
            </div>
            <div class="col-md-3">
                <label>Fees</label>
                <input class="form-control" type="number" id="Fees" name="Fees" value="0.00" required />
            </div>
            <div class="col-md-3">
                <label>Commands</label>
                <br />
                <button id="addrow" class="btn-unique" type="button" name="addrow">Add</button>
                <button id="Delete" class="btn-danger" type="button" name="Delete">Remove</button>
            </div>
        </div>
        <br />
        <div class="row">

            <table class="table table-striped table-bordered table-sm" name="tbl" id="tbl">
                <thead>
                    <tr>
                        <th>Select To Remove</th>
                        <th hidden>
                            ID
                        </th>
                        <th>
                            Subject Name
                        </th>
                        <th hidden>
                            Teacher ID
                        </th>
                        <th>
                            Teacher Name
                        </th>
                        <th>
                            Fees
                        </th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var item in Model.batchSubjects)
                    {
                        <tr>
                            <td>
                                <input type="checkbox" name="record">
                            </td>
                            <td>
                                @Html.DisplayFor(modelItem => item.SubjectId)
                            </td>
                            <td>
                                @Html.DisplayFor(modelItem => item.Subject.SubName)
                            </td>
                            <td hidden>
                                @Html.DisplayFor(modelItem => item.teacherId)
                            </td>
                            <td>
                                Teacher name
                            </td>
                            <td>
                                Fees
                            </td>
                        </tr>
                    }
                </tbody>



            </table>

        </div>
    </div>

    <div class="col-md-12" style="text-align: end; padding-top:2em;
     background-color:lavender; vertical-align:central">

        <button type="button" class="btn-green" style="border-radius: 10px;"
                id="btnPost" name="btnPost">
            Submit
        </button>

        @*<button class="btn-danger" style="border-radius: 10px;"
                    onclick="location.href='@Url.Action("Index", "Batch")'">
            Reset</button>*@
    </div>
</div>

}


@section Scripts {

    <script type="text/javascript">

        $(document).ready(function () {
            $("#StanderdId").empty();
            $("#SubjectId").empty();
            $("#BoardId").val(-1);
            $("#TeacherId").val(-1);

           
            $("#btnPost").click(function () {
                var Batch = new Object();
                Batch.BatchName = $('#BatchName').val();
                Batch.FromDate = $('#FromDate').val();
                Batch.ToDate = $('#ToDate').val();
                Batch.BoardId = $('#BoardId').val();
                Batch.StandardId = $('#StanderdId').val();
                Batch.MaxStudent = $('#MaxStudent').val();
                //Loop through the Table rows and build a JSON array.
                var Table = new Array();
                $("#tbl TBODY TR").each(function () {
                    var row = $(this);
                    var Subjects = {};
                    Subjects.SubjectId = row.find("TD").eq(1).html();
                    Subjects.TeacherId = row.find("TD").eq(3).html();
                    Subjects.Fees = row.find("TD").eq(5).html(); 
                    Table.push(Subjects);
                });

            //Send the JSON array to Controller using AJAX.
                Batch.batchSubjects = Table;
                
                if (Batch != null) {
                    $.ajax({
                        type: "POST",
                        url: "/Batch/Create",
                        data: JSON.stringify(Batch),
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (response) {
                            if (response != null) {
                                alert("Batch Successfully Created !!!"); 
                            } else {
                                alert("Something went wrong");
                            }
                        },
                        failure: function (response) {
                            alert(response.responseText);
                        },
                        error: function (response) {
                            alert(response.responseText);
                        }
                    });
                }
            });

        });
    </script>
}


And Belwo is the Controller Method

 [HttpPost]
        public ActionResult Create(BatchModel batch)
        {
            BatchMaster bm = new BatchMaster();
            bm.MaxStudent = batch.MaxStudent;
            bm.BatchName = batch.BatchName;
            bm.BoardId = batch.BoardId;
            bm.StandardId = batch.StandardId;           
            bm.FromDate = batch.FromDate;
            bm.ToDate = batch.ToDate;
            bm.Id = Guid.NewGuid();

            if (bm.StandardId>0)
            {
                db.Batches.Add(bm);

                foreach (var item in batch.batchSubjects)
                {
                    BatchSubjects BS = new BatchSubjects();
                    BS.Id = Guid.NewGuid();
                    BS.BatchId = bm.Id.ToString();
                    BS.SubjectId = item.SubjectId;
                    BS.teacherId = item.teacherId;
                    BS.fees = item.fees;

                    db.batchSubjects.Add(BS);
                }
                db.SaveChanges();

                return RedirectToAction("BatchList");
            }
            //Below Code Added on 02-09-2022
            else
            {
              return RedirectToAction("Create");
            }


            
        }

I am getting Error A public action method content was not found on controller MDBLandingPage.Controllers.BatchController when I am debugging Code then debugger skipping some line and jumping to Next lines again it comes back it happens two times in same method. data is Inserting correctly but not redirecting to List view.

0 Answers
Related