cruds

Sep 19, 2011 at 6:26 PM
Hello, 

I'm having some trouble understanding the cruds generation. I basically want the MealsLookup screen to allow a user to create meals, functionality already present if the user clicks on the Meals link and hits "create" on that screen. This pops up a "create" popup which works fine. I want to call this view and controller from the MealsLookup screen.

First, I created a custom SearchForm.ascx within my MealsLookup folder.

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<label><%=Mui.Search %>: </label>
<input type="text" name="search" />
<input type="submit" value="<%=Mui.Search %>" />
<%=Html.PopupFormActionLink("create", Mui.Create_Meal, controller: "Meal" ,htmlAttributes: new { @class = "abtn", style = "padding:0.38em 1em" })%>
<br />
<div style="height:5px;" />

Second, I went to MealsLookupController and added this override:

public override ActionResult SearchForm()
        {
            //go to modified search form instead of the default in Shared/Awesome
            return View(@"SearchForm");
        }

Now, the app correctly redirects to this custom SearchForm on which I'm attempting to call the Meal controller and View.

I get the error "callpfcreatemeal" undefined. I realize I'm probably misunderstanding an MVC basic here, but i'm unclear what I have to do outside of telling it to look for the "meal" controller to point it to the right spot.

Thanks as always.

Coordinator
Sep 19, 2011 at 8:45 PM

you have the <%=Html.PopupFormActionLink

which requires for you to do Html.MakePopupForm before

learn this: http://awesome.codeplex.com/wikipage?title=PopupForm&referringTitle=Home

Sep 19, 2011 at 8:55 PM

Excellent, I will try this! Thank you. Those project awesome wiki pages are all very useful.

Sep 20, 2011 at 2:07 PM

I used the link you gave me and studied the crudere controller to see how you built your create function and arrived at this code:

<%=Html.MakePopupForm<MealController>(input => input.Create(), successFunction: "create", fullScreen:true)%>
<%=Html.PopupFormActionLink<MealController>(input => input.Create(), Mui.Create_Participant, new { @class = "abtn", style = "padding:0.38em 1em" })%>

This successfully lets me create meals from the MealLookup screen. The trouble I'm having is that after I create the new meal I need to refresh the underlying Meal multi lookup to display the newest created meal. 
I'm having trouble finding where this code is.

PopupForm.ascx has function OnSuccess which calls Model.RefreshOnSuccess but that doesn't seem to be executing or I'm not hooking into it to force the refresh.

Any ideas?

Coordinator
Sep 20, 2011 at 5:53 PM

try clicking the search button with js or do  a submit() of the searchform

Sep 20, 2011 at 7:22 PM

Thanks!

Submit closed the search form instead of refreshing but a click event on the "search" button with JS did the trick.

 

Here is the complete code:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<label><%=Mui.Search %>: </label>
<input type="text" name="search" />
<input type="submit" id="submit" value="<%=Mui.Search %>" />
<%=Html.MakePopupForm<MealController>(input => input.Create(), successFunction: "clickSearch", fullScreen:true)%>
<%=Html.PopupFormActionLink<MealController>(input => input.Create(), Mui.Create_Participant, new { @class = "abtn", style = "padding:0.35em 1em" })%>
<script type="text/javascript">
    function clickSearch() {
        var btn = document.getElementById('submit');
        if (btn) 
        {
            btn.click();
        }
    }
</script>
<br />
<div style="height:5px;" /> 

This allows me to add meals on the fly from the MealsLookup screen, wherever that may be called.

You rock. Thanks again. 

Sep 21, 2011 at 2:17 PM

One additional note pertaining to popupforms... The MakePopupForm generates a div under certain conditions(like once validation is triggered) which in both IE and Chrome will push the popup action link button down

The resolution to this is to call MakePopupForm AFTER the PopupFormActionLink, so it doesn't screw up your divs.

Coordinator
Sep 21, 2011 at 4:58 PM

you can call wherever you want, the important thing is to call it just once  and actionlink as many times as you need