Friday, June 14, 2013

How to export html table into Excel file in ASP.MVC?

        public ActionResult ExportToExcel(int id)
        {
            string sb = "html table tag in here";
            byte[] buffer = System.Text.Encoding.UTF8.GetBytes(sb.ToString());
            return File(buffer, "application/vnd.ms-excel");
        }

How to render a view into a string in ASP.NET MVC?


        protected string RenderPartialViewToString(string viewName, object model)
        {
            if (string.IsNullOrEmpty(viewName))
                viewName = ControllerContext.RouteData.GetRequiredString("action");

            ViewData.Model = model;

            using (StringWriter sw = new StringWriter())
            {
                ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
                ViewContext viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
                viewResult.View.Render(viewContext, sw);

                return sw.GetStringBuilder().ToString();
            }
        }

How to set default value to a radio button in ASP.NET MVC 3

            Yes
            @Html.RadioButtonFor(model => model.TermsAndConditions, "True")
            No
            @Html.RadioButtonFor(model => model.TermsAndConditions, "False", new { Checked = "checked" })
             

How many number data type in Javascript?


Only one. All numbers in Javascript are 64bit (8 bytes) floating point numbers