0

First of all I want to say that I'm a total noob when it comes to working with javascript, and it's my first time when I'm using popup in a project.

I did this until now (Index view):

<button type="button" class="btn btn-info btn-xs" data-toggle="modal" data-target="#enquirypopup">Add Event</button>//Table with the list of entries.
<div id="enquirypopup" class="modal fade in" role="dialog" tabindex="-1">
    <div class="modal-dialog">

        <!-- Modal content-->
        <div class="modal-content row">
            <div class="modal-header custom-modal-header">
                <button type="button" class="close" data-dismiss="modal">×</button>
                <h4 class="modal-title">Add Event</h4>
            </div>
            <div class="modal-body">
            //This is only a bit off what I have tried
                @*<form name="info_form" class="form-inline" action="#" method="post">*@
                @*<form name="info_form" class="form-inline" action="Project/Areas/User/Events/Add" method="post">*@
                @*<form name="info_form" class="form-inline" action="@Url.Action("Index", "Events")" method="post">*@
                @*<form name="info_form" class="form-inline" action="@Url.Action("Add")" method="post">*@
                
                <form name="info_form" class="form-inline" action="/Events/Add" method="post">
                    <div class="form-group col-sm-12">
                        <label>Event Title: </label>
                        <br />
                        <input type="text" class="form-control" name="Event" id="Event" placeholder="Event Name">
                    </div>
                    <br />
                    <br />
                    <div class="form-group col-sm-12">
                        <label>Starting Date and Time: </label>
                        <br />
                        <input type="text" class="form-control" name="Start_Date" id="Start_Date" placeholder="ll/zz/aaaa hh:mm:ss">
                    </div>
                    <br />
                    <br />
                    <div class="form-group col-sm-12">
                        <label>Ending Date and Time: </label>
                        <br />
                        <input type="text" class="form-control" name="End_Date" id="End_Date" placeholder="ll/zz/aaaa hh:mm:ss">
                    </div>
                    <br />
                    <br />
                    <div class="modal-footer">
                        @*<div class="form-group col-sm-12">*@
                        <button type="submit" class="btn btn-success pull-right">Save</button>
                        @*</div>*@
                    </div>
                </form>
            </div>

        </div>

    </div>
</div>

And here is the controller:

public ActionResult Index()
    {
        return View(db.tbl_Event.ToList());
    }

[HttpGet]
    //public PartialViewResult Add()
    public ActionResult Add()
    {
        //return PartialView("_Event");
        return View();
    }

    [HttpPost]
    //public PartialViewResult Add(BOL3.tbl_Event eve)
    public ActionResult Add(BOL3.tbl_Event eve)
    {
        db.tbl_Event.Add(eve);
        db.SaveChanges();

        //return Add();
        //return View("Index");
        //return View();
        return RedirectToAction("Index", eve);
    }

When I Save the entered data into the popup, it shows error: "The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched: bla/bla/bla", but it doesn't show the corect path to the index view. So that is my problem, when I save the data I want to close the popup and the value to be displayed in the list(Index view). Please help me with this, because I have searched many websites to help me do this but nothing worked for me.

halfer
  • 19,824
  • 17
  • 99
  • 186
Jon A
  • 137
  • 2
  • 11
  • The issue is with your `return View("Index", eve);` line. The `Index` view is not being found within the `Views/[ControllerName]` or `Views/Shared` folder. – Rory McCrossan Mar 27 '17 at 07:36
  • Do you have an `Index.cshtml` file in that controller? And you should be redirecting to an `Index()` method, not returning the view. –  Mar 27 '17 at 07:37
  • Yes I have the index in that controller. – Jon A Mar 27 '17 at 07:38
  • Ok let me tri redirecting – Jon A Mar 27 '17 at 07:39
  • It displays the same error with "return RedirectToAction("Index", eve);" – Jon A Mar 27 '17 at 07:43
  • I think the problem is in action from here: "
    ".
    – Jon A Mar 27 '17 at 07:44
  • It makes no sense to return a model to the `Index()` method. And show your `Index()` method (and what is your `Add()` GET method for - how and where is that being called?) –  Mar 27 '17 at 07:45
  • the get method I used it for the partial view(another thing that I have tryed but didn't work). – Jon A Mar 27 '17 at 07:47
  • This is the Index method: " // GET: User/Events public ActionResult Index() { return View(db.tbl_Event.ToList()); } " – Jon A Mar 27 '17 at 07:48
  • Edit your question with the relevant code. And `// GET: User/Events` suggests its in `UserController`, yet your calling a method in `EventsController` - or do you have areas involved (and why are your manually generating your html instead of using the `HtmlHelper` methods?) –  Mar 27 '17 at 07:56
  • Like I said it's my first time using this popup so I really don't know how to do it in a corect way. The User is the folder in wich the controller is (using Areas). – Jon A Mar 27 '17 at 07:58
  • 1
    I found out what was wrong with it following this tutorial: "https://www.youtube.com/watch?v=HGUgZqJUBkI". Thank you everybody that tried to help me solve this! – Jon A Mar 28 '17 at 07:17
  • Please consider summarising what you found in the video to solve this, and put that as an answer below. We don't use [solved] devices in titles here, as we have an acceptance system instead. Thanks! – halfer Mar 28 '17 at 19:48

0 Answers0