Note that there are some explanatory texts on larger screens.

plurals
  1. POusing ByRef over ByVal to hit a database
    primarykey
    data
    text
    <p>I'm using an ajax call to hit a database to load a drop down. Now, this is something we're going to be doing a lot where I work now that someone's figured out how to do it.</p> <p>My supervisor has asked me to try and make my ajax call one that I can easily use for multiple pages and such without having to redo the code for each new page. My code:</p> <p><strong>Controller</strong></p> <pre><code>Function Index(ByVal KovID As String) As JsonResult Dim db As New Database1Entities Dim record As New List(Of BodyStyle) record = (From b In db.BodyStyles Where b.KovID = KovID Select b).ToList Return Json(record, JsonRequestBehavior.AllowGet) End Function </code></pre> <p><strong>JQuery</strong></p> <pre><code>function ajaxSuccess(record) { var drop2 = $('#Vehicle_BodyStyle_value'); drop2.get(0).options.length = 0; drop2.get(0).options[0] = new Option("Please Select One", "-1"); $.each(record, function (index, item) { drop2.get(0).options[drop2.get(0).options.length] = new Option(item.BodyStyle1, index); }); } function ajaxError() { $('#Vehicle_BodyStyle_value').get(0).options.length = 0; $('#Vehicle_BodyStyle_value').get(0).options[0] = new Option("Error!", "-1"); alert("Failed to load styles"); } $('#Vehicle_KovId_value').change(function () { var kovID = $(this).val(); var drop2 = $('#Vehicle_BodyStyle_value'); if (kovID != null &amp;&amp; kovID != '') { drop2.get(0).options.length = 0; drop2.get(0).options[0] = new Option('Please Select One', '-1'); $.ajax({ type: "GET", url: '/Ajax/Index', async: false, data: { KovID: kovID }, contentType: "application/json; charset=utf-8", success: ajaxSuccess, error: ajaxError }); } }); </code></pre> <p>Now, I don't know VB.NET. In fact, a coworker helped me with the controller, and he's not here to assist further in this matter.</p> <p>My question, posed by my supervisor, is how can we make this work?</p> <p>If the <code>ByVal</code> in the controller class is changed to a <code>ByRef</code>, can we pass something in for the <code>data:</code> line in the ajax call so that this code can be reused and not rewritten?</p> <p>Any help or clarification will be greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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