Thursday 11 April 2019

Creating master or common menu in html only website

Html does not have master page like feature, so you might end up creating menu on each page.
But with help of javascript you can  do a work arround

Paste your menu code in seperate file and do next after the DOM load

$(document).ready(function () {
    //adds Main-manu.html content into any "#MainMenu" element
    $('#MainMenu').load('Main-manu.html'); 
});

Tuesday 9 April 2019

Render partial view at server side and set to view dynamically

Well this is a situation where the .net framework come into picture.
There is a condition where you have to return a data object as well as a partial view in any of your action method in controller.
Do like this - 

public string RenderPartialView(string viewName, object model)
        {
            ViewData.Model = model;
            using (var sw = new StringWriter())
            {
                var viewResult = ViewEngines.Engines.FindPartialView(ControllerContext,viewName);
                var viewContext = new ViewContext(ControllerContext, viewResult.View,ViewData, TempData, sw);
                viewResult.View.Render(viewContext, sw);
                viewResult.ViewEngine.ReleaseView(ControllerContext, viewResult.View);
                return sw.GetStringBuilder().ToString(); // this line return exactly the html of partial view with data
            }
        }
public ActionResult Create(ProductModel model, int type)
        {
            string msg = "";  
            msg = GetUIMessageString(type);
            return Json(new { msg, table = RenderPartialView("_ProductList", model) }); // returns a json to view and partial view as html string     
        }

Note:  Try to place the RenderPartialView() method in a class where all your controllers can access it like -  in a parent class.

How I started

I used to spend hours on the internet, on various web sites, trying to understand code.
To me, to become successful in IT your knowledge of coding must be inimitable.
Things changed when I changed my first company.

Now after 5 years, I say, for successful career in IT your knowledge of how to code must be on par with any other IT guy with 10 or 15 years of knowledge.

Well this sound too much, right?
But as the saying goes, "Aim for the stars and you might hit the MOON"

Live my short, ongoing ride in IT with me.
Life of a engineer

Send All Azure App Insights Or Logs Data To Tool Like Datadog

  Introduction Microsoft Azure provides a variety of insights and monitoring logs that you can monitor to check the state of a resource and ...