ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Popup will not close
Title:
B
I
{code}
?
Hi, Here is my View: @{ ViewBag.Title = "Index"; } <h2>Index</h2> @Html.Awe().InitPopupForm().Name("createSeason").Group("Season").Url(Url.Action("Create")).Success("itemCreated('SeasonGrid')").Title("create season").Height(500) @Html.Awe().InitPopupForm().Name("editSeason").Group("Season").Url(Url.Action("Edit")).Success("refreshGrid('SeasonGrid')").Title("edit season").Height(500) @Html.Awe().InitPopupForm().Name("deleteSeason").Url(Url.Action("Delete")).Success("refreshGrid('SeasonGrid')").Height(200).Parameter("gridId", "SeasonGrid").Title("delete season") <div class="bar"> <button type="button" class="awe-btn" onclick="awe.open('createSeason')">Create</button> </div> @{ //used by the grid actions const string DeleteFormat = "<button type='button' class='awe-btn' onclick=\"awe.open('deleteSeason', { params:{ Id .Id } })\"><span class='ico-del'></span></button>"; const string EditFormat = "<button type='button' class='awe-btn' onclick=\"awe.open('editSeason', { params:{ Id .Id } })\"><span class='ico-edit'></span></button>"; } @Html.Awe().Grid("SeasonGrid").Height(350).Url(Url.Action("GetSeasons")).Groupable(false).Columns( new Column { Name = "Id", Header = "Id", Width = 50 }, new Column { Name = "SeasonName", Header = "Season Name" }, new Column { ClientFormat = EditFormat, Width = 50 }, new Column { ClientFormat = DeleteFormat, Width = 50 }) @section Scripts{ <script type="text/javascript"> function refreshGrid(gridId) { return function () { $('#' + gridId).data('api').load(); }; } function itemCreated(gridId) { return function () { $('#' + gridId).data('api').load({ sort: [], oparams: { page: 1 } }); }; } </script> } And here is my controller: public class SeasonController : Controller { private ApplicationDbContext db = new ApplicationDbContext(); public ActionResult Index() { return View(); } public ActionResult GetSeasons(GridParams g) { var list = db.Seasons.Where(s => s.IsCreated).OrderBy(s => s.SeasonName).AsQueryable(); return Json(new GridModelBuilder<Season>(list, g) { Key = "SeasonName" // needed for Entity Framework, nesting, tree, grid api (select, update) // EF can't do paging unless it orders at least by one column so we will order by that column when there is no sorted columns }.Build()); } public ActionResult Create() { // needed so we could add addresses even before the restaurant is created/saved var season = new Season(); db.Seasons.Add(season); db.SaveChanges(); return PartialView("Create", new Season { Id = season.Id }); } [HttpPost] public ActionResult Create(Season input) { if (!ModelState.IsValid) { return View(input); } var season = db.Seasons.Find(input.Id); season.SeasonName = input.SeasonName; season.IsCreated = true; db.SaveChanges(); return Json(new { }); } } The record gets saved to the database but the popup doesn't close and therefore my grid doesn't refresh. I can see the following in the console when the form loads: Empty string passed to getElementById(). And the following when ok is pressed: TypeError: $(...).data(...) is undefined I can't see where I'm going wrong with what I have though? Can you help? If I am successful in getting this working you have found yourself another customer! :) Kind Regards, Paul Pitchford.
Save Changes
Cancel
pitchford.paul
asked at 27 Feb 2015
if you get an error in the console when the popup loads, it means that you have something in the create view that causes the problem, maybe you have some incorrect js in there, duplicate ids, or you load the masterpage again with all the scripts, etc.
at 27 Feb 2015
Omu
also if you're on razor, and using _viewstart.cshtml make sure you use return PartialView() (instead of return View) for all the CRUD views that open in popups (Create/Edit/Delete) otherwise when loading the popup you also load the Layout again with all the scripts, and that causes problems (http://stackoverflow.com/a/4082220/112100)
at 01 Mar 2015
Omu
Yes, I presumed this could be a problem so thought about that already. It didn't fix the problem. I've emailed you via the contact form with a question. Hopefully you can help and we can progress. Thank you.
at 01 Mar 2015
pitchford.paul
please try this new MVC5 Grid Crud Demo http://awesome.codeplex.com/downloads/get/1435235
at 01 Mar 2015
Omu
Did you receive my email? Paul Pitchford.
at 02 Mar 2015
pitchford.paul
yes, please download the demo mentioned above, it's a bare minimum mvc5 razor crud demo, I know you requested master-child but this should be enough (and it's simpler as a demo)
at 02 Mar 2015
Omu
does your Create view have a hidden input for the Season.Id, is the season getting saved in the get action or in the post action also after you entered data, could you show your Create view
at 02 Mar 2015
Omu
Thank you for your help. I missed the previous link somehow. That was just what I needed. As soon as I return from my holiday, I'll place the order. I'm also using ValueInjecter. Thank you so much for your help! Paul.
at 03 Mar 2015
pitchford.paul
You're welcome, so what was causing the problem for you ?
at 03 Mar 2015
Omu
I'm not certain. I had the AwesomeMvc comp reg'd correctly and as far as I can see I had all the scripts loaded as suggested. I think the "Empty string passed to getElementById()" in the Firefox console was a red hearing as I get that when the popup opens in the example you gave to me. At a guess, I'd suggest I just had some css setup wrong as the popup didn't look perfect either. I love ValueInjecter, what a lot of coding that saves, brilliant! I stumbled onto it today by chance and noticed it was by you too. A perfect companion for passing ViewModel data back to the repository. Paul.
at 03 Mar 2015
pitchford.paul
Answers
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK