I'm struggling to figure out how I should create my partial views that use jQuery.
For example, in a partial view below, I show a text box that connects to the jquery autocomplete plugin.
In the end, I want the results to appear next to them next to an “X”, which the user can delete, but for this example, the selected text is simply added to the div div.
Is my jQuery OK code sitting here in a partial view, or should I put it in an external file? If an external file is used, another developer using a partial view should know that the external js file should be included - is this normal?
I suppose my question is actually that although I'm kind of OK with jQuery (finding elements in the DOM, calling asynchronously, etc.), I need some guidance on where to put all this code That will stop me in a mess.
Does what I just printed make sense ????
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
$(".acEmployee").autocomplete({
source: ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"],
select: function(event, ui) {
$(this).siblings().append(ui.item.value);
}
});
});
</script>
<div><div></div><input class="acEmployee" /></div>
source
share