Skip to main content

Posts

Smooth Scrolling To Internal Links With jQuery

jQuery allows you change the way you interact with your website with very little code. jQuery has an animate function which allows you to animate anything that jQuery does, including scrolling. Animate scrolling creates a better effect to the visitor than to just job to a place on the page. There are many websites that will use internal links to jump to different parts of the page this is done by using a # and then the element id in the anchor tag. < a href = " #services " > Jump to services </ a > < div id = " services " > </ div > Doing the above creates a link that will move the page to the services div when you click it. But it jumps to this position and if it's far down the page it's not the nicest effect to the visitor. It's better if you can actually scroll to this position to help the visitors see where this is positioned. In jQuery if you set an animation on the scroll event then it creates a scrolling...

Count characters/sms using jQuery

HTML: <textarea name = "message" value = "" id = "message" ></textarea> <p> <span id = "remaining" > 160 characters remaining </span> <span id = "messages" > 1 message(s) </span> </p> jQuery: $ ( document ). ready ( function (){ var $remaining = $ ( '#remaining' ), $messages = $remaining . next (); $ ( '#message' ). keyup ( function (){ var chars = this . value . length , messages = Math . ceil ( chars / 160 ), remaining = messages * 160 - ( chars % ( messages * 160 ) || messages * 160 ); $remaining . text ( remaining + ' characters remaining' ); $messages . text ( messages + ' message(s)' ); }); }); See jsFiddle example. Ref:  http://stackoverflow.com/questions/4705185/count-characters-sms-using-jquery

In MVC3 Razor, how do I get the html of a rendered view inside an action?

I use a static method in a class I called  Utilities.Common  I pass views back to the client as properties of JSON objects constantly so I had a need to render them to a string. Here ya go: public static string RenderPartialViewToString ( Controller controller , string viewName , object model ) { controller . ViewData . Model = model ; using ( StringWriter sw = new StringWriter ()) { ViewEngineResult viewResult = ViewEngines . Engines . FindPartialView ( controller . ControllerContext , viewName ); ViewContext viewContext = new ViewContext ( controller . ControllerContext , viewResult . View , controller . ViewData , controller . TempData , sw ); viewResult . View . Render ( viewContext , sw ); return sw . ToString (); } } This will work for full views as well as partial views, just change  ViewEngines.Engines.FindPartialView  to  ViewEngines.Engines.FindView . FindView ne...

How to download .xslx File from server using EPPlus and MVC - stream Response

All you need to do is reset the stream position.  stream.Position = 0; You  shouldn't write directly to the Response , it's not the MVC way. It doesn't follow the correct MVC pipeline and it tightly couples your controller action code to the Response object. When you add a file name as the 3rd parameter in  File() , MVC automatically adds the correct  Content-Disposition  header... so you shouldn't need to add it manually. The short of it is, this is what you want: public ActionResult Index () { using ( ExcelPackage package = new ExcelPackage ()) { // I populate the worksheet here. I'm 90% sure this is fine // because the stream file size changes based on what I pass to it. var stream = new MemoryStream (); package . SaveAs ( stream ); string fileName = "myfilename.xlsx" ; string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet...

SQL SERVER – Query to Find First and Last Day of Current Month

Following query will run respective to today’s date. It will return Last Day of Previous Month, First Day of Current Month, Today, Last Day of Previous Month and First Day of Next Month respective to current month. DECLARE  @mydate  DATETIME SELECT  @mydate  =  GETDATE () SELECT  CONVERT ( VARCHAR ( 25 ), DATEADD ( dd ,-( DAY ( @mydate )), @mydate ), 101 ) , 'Last Day of Previous Month' UNION SELECT  CONVERT ( VARCHAR ( 25 ), DATEADD ( dd ,-( DAY ( @mydate )- 1 ), @mydate ), 101 ) AS  Date_Value , 'First Day of Current Month'  AS  Date_Type UNION SELECT  CONVERT ( VARCHAR ( 25 ), @mydate , 101 )  AS  Date_Value ,  'Today'  AS Date_Type UNION SELECT  CONVERT ( VARCHAR ( 25 ), DATEADD ( dd ,-( DAY ( DATEADD ( mm , 1 , @mydate ))), DATEADD ( mm , 1 , @mydate )), 101 ) , 'Last Day of Current Month' UNION SELECT  CONVERT ( VARCHAR (...