Bind Hyperlink (Anchor Tag) from database in ASP.Net MVC

Last Reply 7 months ago By dharmendr

Posted 7 months ago

Hi,

I have one table with relevant fields

Id    ControllerName      Url  

1     Report                    /report/Index/

2      Report1                 /report1/Index1/

Currently my requirement is that

i need to fecth values from database and replace li elements(URl and controllername)

My expecyted o/p after fecthing values from data 

<h4>An Unordered List:</h4>
<ul>
    <li><a href="/report/Index/">Report</a></li>
    <li><a href="/report1/Index/">Report1</a></li>
</ul>

This was the my code

<!DOCTYPE html>
<html>
<body>
    <h4>An Unordered List:</h4>
    <ul>
        <li><a href="/report/Index/">Report</a></li>
        <li><a href="/report1/Index/">Report1</a></li>
    </ul>
</body>
</html>

 

        public JsonResult getAll()
        {
            db.Configuration.ProxyCreationEnabled = false;
            using (ReportEntities dataContext = new ReportEntities())
            {
                var employeeList = (from E in dataContext.MenuSelections                                    
                                    orderby E.Id
                                    select new
                                    {
                                        E.Id,
                                        E.ControllerName,
                                        E.Url
                                    }).ToList();
                var JsonResult = Json(employeeList, JsonRequestBehavior.AllowGet);
                JsonResult.MaxJsonLength = int.MaxValue;
                return JsonResult;
            }
        }        

I need o/p using javascript and MVC

Could you please help me

This question does not have replies that have been liked.