ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Save/validate master form on Add child click in Master Detail Crud
Title:
B
I
{code}
?
in your example link: http://demo.aspnetawesome.com/MasterDetailCrudDemo how to do this: 1. user clicks Create button, Popup opens 2. user no write something in Name textbox 3. user clicks [add address] button. 3.1 not allow open pop-up [address]. 3.2 have to warn User this moment, user to fill name text box for continued (using [DataAnnotations] to validate)
Save Changes
Cancel
Leonel Jaime
asked at 25 Aug 2015
Answers
B
I
{code}
?
using the demo, make these changes: in MasterDetailCrudDemo\Create.cshtml @model AwesomeMvcDemo.ViewModels.Input.RestaurantInput <div id="mainform"> @using (Html.BeginForm()) { //can't use Html.Hidden mvc will override the changed value from server <input type="hidden" name="Id" value="@Model.Id"/> @Html.EditorFor(o => o.Name) <input type="hidden" name="returnView" /> } </div> @Html.InitCrudPopupsForGrid("AddressesGrid", "AddressesGridCrud", 230) <div class="bar"> @if(ViewData["create"] != null) { <button id="masterSubmit" type="button" class="awe-btn">Add address</button> <script> $('#masterSubmit').click(function () { $('#mainform [name=returnView]').val('true'); $('#mainform form').submit(); }); </script> } else{ <button type="button" class="awe-btn" onclick="awe.open('createAddressesGrid', { params: {restaurantId: '@(Model.Id)' }})">Add address</button> } </div> @if (ViewData["addChild"] != null) { <script>awe.open('createAddressesGrid', { params: { restaurantId: '@(Model.Id)' } })</script> } MasterDetailCrudDemoController.cs public ActionResult Create() { ViewData["create"] = 1; return PartialView(new RestaurantInput()); } [HttpPost] public ActionResult Create(RestaurantInput input, bool? returnView) { if (!ModelState.IsValid) { ViewData["create"] = 1; return PartialView(input); } Restaurant restaurant; if (input.Id == 0) { restaurant = new Restaurant { Name = input.Name, IsCreated = true }; Db.Insert(restaurant); input.Id = restaurant.Id; if (returnView.HasValue) { ViewData["addChild"] = 1; return PartialView(input); } } else { restaurant = Db.Get<Restaurant>(input.Id); restaurant.Name = input.Name; Db.Update(restaurant); } return Json(restaurant); // use MapToGridModel like in Grid Crud Demo when grid uses Map }
Save Changes
Cancel
Omu
answered at 25 Aug 2015
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