Error-System.InvalidOperationException The View Create was not found RRS feed

  • Question

  • User1979860870 posted


            public ActionResult Create_Post(Location objLocation)
                    if (ModelState.IsValid)
                        return new JsonResult(objLocation);
                        var allErrors = ModelState.Values.SelectMany(v => v.Errors.Select(b => b.ErrorMessage));
                catch (System.Data.DataException)
                    ModelState.AddModelError("", "Unable to Save Changes. Try Again, and if the problem persists contact System Administrator.");
                return View();
    function Add() {
        var objLocation = {
            Name: $('#Name').val(),
            Street: $('#Street').val(),
            City: $('#City').val(),
            url: "/Location/Create",
            data: JSON.stringify(objLocation),
            type: "POST",
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            success: function (result) {
            error: function (errormessage) {

    ****************** VIEW

    <div>@model IEnumerable<Employee_Management.Models.Location></div> <div> </div> <div>@{</div> <div>    ViewData["Title"] = "Index";</div> <div>}</div> <div> </div> <div><div class="container"></div> <div>    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal" onclick="clearTextBox();">Add New Location</button><br /><br /></div> <div>    <table class="table table-bordered table-hover"></div> <div>        <thead></div> <div>            <tr></div> <div>                <th></div> <div>                    Code</div> <div>                </th></div> <div>                <th></div> <div>                    Name</div> <div>                </th></div> <div>                <th></div> <div>                    Street</div> <div>                </th></div> <div>                <th></div> <div>                    City</div> <div>                </th></div> <div>                <th></div> <div>                    State</div> <div>                </th></div> <div>                <th></div> <div>                    Zip</div> <div>                </th></div> <div>                <th></div> <div>                    Country</div> <div>                </th></div> <div>                <th></div> <div>                    PanNo</div> <div>                </th></div> <div>                <th></div> <div>                    GstRegNo</div> <div>                </th></div> <div>                <th></div> <div>                    Mobile</div> <div>                </th></div> <div>                <th></div> <div>                    Phone-1</div> <div>                </th></div> <div>                <th></div> <div>                    Phone-2</div> <div>                </th></div> <div>                <th></div> <div>                    EMail</div> <div>                </th></div> <div>                <th></div> <div>                    Action</div> <div>                </th></div> <div>            </tr></div> <div>        </thead></div> <div>        <tbody class="tbody"></div> <div>        </tbody></div> <div>    </table></div> <div></div></div> <div><div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div> <div>    <div class="modal-dialog"></div> <div>        <div class="modal-content"></div> <div>            <div class="modal-header"></div> <div>                <button type="button" class="close" data-dismiss="modal">×</button></div> <div>                <h4 class="modal-title" id="myModalLabel">Add Employee</h4></div> <div>            </div></div> <div>            <div class="modal-body"></div> <div>                <form></div> <div>                    <div class="form-group"></div> <div>                        <label for="Code">Code</label></div> <div>                        <input type="text" class="form-control" id="Code" placeholder="Code"  /></div> <div>                    </div></div> <div>                    <div class="form-group"></div> <div>                        <label for="Name">Name</label></div> <div>                        <input type="text" class="form-control" id="Name" placeholder="Name" /></div> <div>                    </div></div> <div>                    <div class="form-group"></div> <div>                        <label for="Street">Street</label></div> <div>                        <input type="text" class="form-control" id="Street" placeholder="Age" /></div> <div>                    </div></div> <div>                    <div class="form-group"></div> <div>                        <label for="City">City</label></div> <div>                        <input type="text" class="form-control" id="City" placeholder="State" /></div> <div>                    </div></div> <div>                </form></div> <div>            </div></div> <div>            <div class="modal-footer"></div> <div>                <button type="button" class="btn btn-primary" id="btnAdd" onclick="return Add();">Add</button></div> <div>                <button type="button" class="btn btn-primary" id="btnUpdate" style="display:none;" onclick="Update();">Update</button></div> <div>                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button></div> <div>            </div></div> <div>        </div></div> <div>    </div></div> <div></div></div>


    Wednesday, January 20, 2021 7:31 AM


  • User1312693872 posted

    Hi,jagjit saini

    First you should check your post after posting ,or may be it will bring difficulties if others try to view or reproduce it.

    And to the question, do you have the create page? If you return View() in Create action but actually the program does not have that  view,

    this error will occur, you can try RedirectToAction to redirect to an existing page:

            public ActionResult Create_Post(Location objLocation)
                return RedirectToAction("Index");

    Best Regards,

    Jerry Cai

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 20, 2021 9:01 AM