var array = [2, 5, 9]; var index = array.indexOf(2);Then remove it with splice:
array.splice(index,1);
var array = [2, 5, 9]; var index = array.indexOf(2);Then remove it with splice:
array.splice(index,1);
$(‘ul li’).each(function(index){ if ( $(this).hasClass(‘selected’) ) { selected = index; return false; } });
@Html.Partial("ViewName")
@{ Html.RenderPartial("ViewName"); }The usage (using WebForms syntax):
<%: Html.Partial("ViewName") %>
<% Html.RenderPartial("ViewName"); %>Will do exactly the same. You can store the output of Html.Partial in a variable, or return it from a function. You cannot do this with Html.RenderPartial. The result will be written to the Response stream during the execution. The same is true for Html.Action and Html.RenderAction.
Html.RenderPartial( "Partial");You might want an action that returns a partial view if you are using AJAX to load/reload part of a page. In that case, returning the full view is not desired since you only want to reload part of the page. In this case you can have the action just return the partial view that corresponds to that section of the page.
public ActionResult Action(...) { return PartialView( "Partial"); }
if ($.browser.msie && parseInt($.browser.version, 10) === 7) { alert('IE7'); } else { alert('Non IE7'); }
Example: Implements a simple event delegation: The click handler is added to an unordered list, and the children of its li children are hidden. Clicking one of the li children toggles (see toggle()) their children.
<!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-latest.js"></script> </head> <body> <ul> <li>item 1 <ul> <li>sub item 1-a</li> <li>sub item 1-b</li> </ul> </li> <li>item 2 <ul> <li>sub item 2-a</li> <li>sub item 2-b</li> </ul> </li> </ul> <script> function handler(event) { var $target = $(event.target); if( $target.is("li") ) { $target.children().toggle(); } } $("ul").click(handler).find("ul").hide(); </script> </body> </html>
function GetDateFromJSONString(s) { var d = s.replace(/\/Date\(/gi, ''); d = d.replace(/\)\//gi, ''); return new Date(Number(d)); } var s = "\/Date(1342137600000)\/"; alert(GetDateFromJSONString(s));The issue with this is that JavaScript will apply the locale timezone of the client's machine while doing the deserialization which may result in a different Date value. This can be avoided by doing the deserialization bit differrently using JavaScript's toUTCString() method. This function will deserialize it into UTC Date.
var monthNames = { JAN: 0, FEB: 1, MAR: 2, APR: 3, MAY: 4, JUN: 5, JUL: 6, AUG: 7, SEP: 8, OCT: 9, NOV: 10, DEC: 11 } function GetUTCDateFromJSONString(s) { var d = s.replace(/\/Date\(/gi, ''); d = d.replace(/\)\//gi, ''); var utc = new Date(Number(d)).toUTCString(); //Sample value: Mon, 1 Feb 1982 00:00:00 UTC utc = utc.split(',')[1].substring(1).split(' '); utc[0] = utc[3] != '00:00:00' ? Number(utc[0]) + 1 : utc[0]; return new Date(utc[2], monthNames[utc[1].toUpperCase()], utc[0]); } var s = "\/Date(1342137600000)\/"; alert(GetUTCDateFromJSONString(s));
#outer { width: 100%; } #inner { width: 50%; margin: 0px auto; }Of course, you don't have to set the width to 50%. Any width less than the containing div will work. The margin: 0px auto is what does the actual centering. It can be done in a different way as well.
#outer { width: 100%; text-align: center; } #inner { display: inline-block; }That makes the inner div into an inline element that can be centered with text-align.
@helper DisplayPrice(Decimal price) { if(price == 0) { <span>FREE</span> } else { <text> <b>Price:<b> £@(price) </text> } }Click here for more information about the @helper syntax
If you want to import a namespace in your CSHTML file it can be done using @using (C#) or @imports (VB.NET) statement.
C# Example
@using System.Configuration;