Note that there are some explanatory texts on larger screens.

plurals
  1. POmvc3 partial views for search, validate, submit final results
    text
    copied!<p>I am creating a UI using MVC3 to generate a text file message based on user selections. User needs to find a patient by ID, then a provider by name from my db, and then initiate the creation of the text file. I have the message generator working if the right objects are passed to it (separate assembly).</p> <p>I need some help understanding how to implement the search/select/clear logic, and the submission of results to call the generator. (New to MVC3). </p> <p>I made partial views to display the search results, and I have the basic search results showing up on my Index view. </p> <p>Issues: </p> <p>My provider search returns a list of providers by last name &amp; first name, and I need my user to select one, if there are more than one by the name.</p> <p>How do I put these partial views inside a third, to send their results?</p> <p>How can I make it possible to clear results in the partials? How do I make sure that I have a valid value in the partials before I send the result?</p> <p>Any direction would be helpful. Thanks.</p> <p>Here's my HomeController:</p> <pre><code> public class HomeController : Controller { private CrdDatabase db = new CrdDatabase(ConfigurationManager.ConnectionStrings["connectionString_CRD_TEST"].ConnectionString); public PartialViewResult PatientSearch(string clinicNumber) { var patient = db.GetCRDPatientInformation(clinicNumber); if (patient != null) { return PartialView("_PatientSearchResult", patient); } // need to determine how to return an error message/validation message. return PartialView("_PartialClear"); } public PartialViewResult ProviderSearch(string lastName, string firstname) { var providerList = db.GetCRDProviderList(lastName, firstname); if (providerList.Count &lt; 1) { return PartialView("_ProviderSearchResults", providerList); } return PartialView("_PartialClear"); } public ActionResult Index() { return View(); } } </code></pre> <p>Here is the _PatientSearchResult.cshtml partial view:</p> <pre><code>@model Objects.CRDPatientInfo &lt;table id="searchResults"&gt; &lt;tr&gt; &lt;th&gt; Clinic Number &lt;/th&gt; &lt;th&gt; Last Name &lt;/th&gt; &lt;th&gt; First Name &lt;/th&gt; &lt;th&gt; Middle Name &lt;/th&gt; &lt;th&gt; Date of Birth &lt;/th&gt; &lt;th&gt; Admin Gender &lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; @Model.clinic_number &lt;/td&gt; &lt;td&gt; @Model.pat_name_last &lt;/td&gt; &lt;td&gt; @Model.pat_name_first &lt;/td&gt; &lt;td&gt; @Model.pat_name_mid &lt;/td&gt; &lt;td&gt; @Model.pat_birth_date &lt;/td&gt; &lt;td&gt; @Model.pat_gender_code &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>The _ProviderSearchResults.cshtml is similar, except it loops through the list in the model.</p> <p>Here is my Index.cshtml, so far:</p> <pre><code>@{ ViewBag.Title = "Muse Orders Home Page"; } &lt;h2&gt;@ViewBag.Message&lt;/h2&gt; @using (Ajax.BeginForm("PatientSearch", "Home", new AjaxOptions { HttpMethod = "GET", InsertionMode = InsertionMode.Replace, UpdateTargetId = "searchPatientResults" })) { &lt;text&gt;Clinic Number:&lt;/text&gt; &lt;input type="text" name="clinicNumber" /&gt; &lt;input type="submit" name="submitButton" value="Search" /&gt; &lt;input type="submit" name="submitButton" value="Clear" /&gt; } &lt;table id="searchPatientResults"&gt; &lt;/table&gt; @using (Ajax.BeginForm("ProviderSearch", "Home", new AjaxOptions{ HttpMethod = "GET", InsertionMode= InsertionMode.Replace, UpdateTargetId= "searchProviderResults" })) { &lt;text&gt;Provider Last Name:&lt;/text&gt; &lt;input type="text" name="lastName" /&gt; &lt;text&gt;Provider First Name:&lt;/text&gt; &lt;input type="text" name="firstName" /&gt; &lt;input type="submit" name="submitButton" value="Search" /&gt; &lt;input type="submit" name="submitButton" value="Clear" /&gt; } &lt;table id="searchProviderResults"&gt; &lt;/table&gt; @using (Ajax.BeginForm("GenerateOrder", "Home", new AjaxOptions { HttpMethod = "POST", InsertionMode = InsertionMode.Replace, UpdateTargetId = "generateOrder" })) { &lt;input type="hidden" name="patient" /&gt; &lt;input type="hidden" name="provider" /&gt; &lt;input type="submit" name="submitButton" value="GenerateOrder" /&gt; &lt;input type="submit" name="submitButton" value="Clear" /&gt; } &lt;table id="generateOrder"&gt; &lt;/table&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload