I'm using MVC Kendo grid to display a list of items. I can add items one by one fine using the kendo default popup.

Now I would like to be able to add a lot of items in a short time. My idea is to add the first item and be able to keep the popup open to add a second item, and so on.

When I press 'Update' for the first item, I would like to insert this item and reset all the popup field with the default values ready to add a second one.

I am new to Razor. I am doing a project for uni and I am stuck at this point. I cant figure out the way to read value from the option tag. My way of thinking is that the client selects the phone name and then I can display full details of it.

<form name="dropdown" id="dropdown" method="post">

        <table>
            <tr>
                <td><select id="phone1" name="option11">
                    @foreach(var row in db.Query(selectQuery)){
                    <option id="option1" >@row.Brand</option>
                    }
                </select></td>
                <td><select>
                    @foreach(var row in db.Query(selectQuery)){
                    <option value="Phone 2">@row.Brand</option>
                    }
                </select></td>
            </tr>
        </table>
       <input type="submit" class="show-popup" data-showpopup="1" value="Click to Comapre" >
    </form>

I have a Web API 2 API Controller

[RoutePrefix("things")]
public class ThingsController : APIController
{
  [Route("{thingId}", Name="Things.Get")]
  public Thing Get(string thingId)
  {
    //snip...
  }
}

And all is well... except I'd like to pass the URL for that route into some JS so that it can construct URLs to request Things

So in the razor view I've tried

myJavascriptObject.thingUrl = '@Url.Action("Get", "Things", new {area=""})';

but I get a blank string

I've tried giving the controller route an explicit name and using

@Url.RouteUrl("Things.Get", new {areas="", thingId="foo"}") b

ut that's an empty string too.

Am I being silly? Should this work?


Update after more trying of things.

On an MVC controller (Where I need to know the API Controller route)

var something = Url.Action("Get", "Things", new {area = ""});
var somethingWithId = Url.Action("Get", "Things", new { area = "", siteId = "fakeId" });
var somethingElse = Url.RouteUrl(new {Action = "Get", Controller = "Things", Area = ""});
var somethingElseWithId = Url.RouteUrl(new { Action = "Get", Controller = "Things", Area = "", siteId = "fakeId" });

These are all null.

If I remove the area="" condition then I get a route but with the Area name in it and the route doesn't have the area name in it.

?!

I am trying to display the link based on if condition in web grid in asp.net mvc. If the record exceeds end date, then the link is displayed else not.

grid.Column("", format: (item =>
    {
        if (DateTime.Now > item.EndDate)
        {
            Html.ActionLink(
                "File ClAIM",
                "Edit",
                new { id = item.id },
                new { @class = "action-link" });
        }
        return false;
    }))

It is displaying false in all my records.Any help would be appreciated.

I want to create a div from every object in my model, and I need to give them unique IDs for the onclick-method. How do I do this? I tried to put myid inside <%= %> as I read somewhere, it does not work.

This is my code:

@foreach(var r in Model){
   var myid = r.ToString();

   <p class="expand-one" onclick="showhide('<%= myid  %>')" onmouseover="" style="cursor: pointer;">@r.ToSection.Name</p>
               <table id=@myid class="content-one">
                   <tr>
            ......................
             ..................

There is a Common.cshmtl file containing Razor helpers in App_Code folder of my ASP.NET MVC 5 project.

The page view (let it be called Production.cshtml) uses lots of helpers from Common.cshmtl in the way like:

@Common.Helper1();
...
@Common.Helper2();
...
@Common.Helper3();

It is following the recommendations from http://www.asp.net/web-pages/overview/ui,-layouts,-and-themes/creating-and-using-a-helper-in-an-aspnet-web-pages-site

Due to the bug in application code I can see that 2 almost equal AJAX requests are performed after a button click on a page.

I'm getting an error

An exception of type 'System.InvalidOperationException' occurred in mscorlib.dll but was not handled in user code.

An error also claims that the code is trying to modify the collection inside foreach operator. Here it looks like a normal error of application code.

But when debugging the code to find a certain error I can see that it breaks in some very random place of Product.cshtml not connected to the foreach at all. No foreach could be found neither in upper-level and bottom-level files. Also when trying to debug again (without modifications of course) - I can see that the break occured this time in another file - in Common.cshtml ! Repeating again and again prooves this strange behavior.

What could be the reason?

I am very new to MVC design paradigm and I am laying out my first MVC Application which has a Grid full of employees and as soon as you click on each employee on the grid it loads more details about the employee in the Tab control below.

Tab control has three tabs and each represent different aspect of employee information.

Now, I have a different model for List which goes to Grid and then saperate mdoels/partial View combination for each tab in the tab control.

I did go for this design for couple of reason

  1. Saperation of concerns : HTML page design is also like class design and if each HTML piece is on diffrent partial view then the code is more manageable and cleaner
  2. Model Binding is much easier: I can map each partial view to one model and that Model/partial view combo can be loaded and re-loaded without having to worry about other parts on the page.

I think this is very clean and I like it. However, I am not too sure how far or how much aligned I am to best MVC design practices. Is it good a bad design OR it is just a matter of preference. Are there any downsides of doing it this way?

I'll try to keep this short. I am new to MVC.

I have a Controller which creates a list of timeslots (like a schedule), and puts this into a ViewData. I understand how to do this.

I know how to display this data in a drop down menu using @Html.DropDownList, for example my create page has the following:

@Html.DropDownList("TimeSlot", ViewData["TimeSlotsList"] as List<SelectListItem>)
@Html.ValidationMessageFor(model => model.TimeSlot)

My problem is on my index view, it displays the modelItem => item.TimeSlot and shows the value of the Time slot, (1, 2, 3, 4, etc)

@Html.DisplayFor(modelItem => item.TimeSlot)

I want to display the TEXT value of the index from the ViewData[TimeSlotsList] list. Obviously the index will be the value of the modelItem => item.TimeSlot.

I know this would have been much easier if the TimeSlots was its own table in the database but it was not setup this way and at this point in time I can't change without causing myself all kinds of migration headaches, etc.

If anyone knows how to do this or can point me in the right direction it is hugely appreciated! I tried some different ideas but nothing has worked yet.....

EDIT:

I Create the list of timeslots in my controller with this function:

private List<SelectListItem> CreateTimeSlotsList()
        {
            //Build Time Slot Drop Down
            List<SelectListItem> li1 = new List<SelectListItem>();
            li1.Add(new SelectListItem { Text = "10-10:50am, Tues Mar. 17", Value = "1" });
            li1.Add(new SelectListItem { Text = "11-11:50am, Tues Mar. 17", Value = "2" });
            li1.Add(new SelectListItem { Text = "1:10-2pm, Tues Mar. 17", Value = "3" });
            li1.Add(new SelectListItem { Text = "2:10-3pm, Tues Mar. 17", Value = "4" });
            li1.Add(new SelectListItem { Text = "3:30-4:20pm, Tues Mar. 17", Value = "5" });
            li1.Add(new SelectListItem { Text = "8:30-9:20am, Wed Mar. 18", Value = "6" });
            li1.Add(new SelectListItem { Text = "9:30-10:20am, Wed Mar. 18", Value = "7" });
            li1.Add(new SelectListItem { Text = "11-11:50am, Wed Mar. 18", Value = "8" });
            li1.Add(new SelectListItem { Text = "1:10-2pm, Wed Mar. 18", Value = "9" });
            li1.Add(new SelectListItem { Text = "2:10-3pm, Wed Mar. 18", Value = "10" });
            li1.Add(new SelectListItem { Text = "Hands On/Demo", Value = "99" });
            ViewData["timeSlots"] = li1;
            return (li1);
        }

Then i use

ViewData["TimeSlotsList"] = CreateTimeSlots();

I want to display the TEXT value of the index of the above list.

I placed a RenderAction inside my layout page:

@{Html.RenderAction( "LoginPartial", "Account" );}

The controller method looks like this but never seems to be called. The AccountController on the other hand does:

public ActionResult LoginPartial()
{            
    ApplicationUser user = this.userRepository.GetByID( User.Identity.GetUserId() );
    return PartialView( "_LoginPartial", user );
}

The view looks like this:

@model Test.Domain.Entities.ApplicationUser

@using Microsoft.AspNet.Identity

@{
    Layout = "";
}

...

When i run the application, I get:

HTTP Error 404.15 - Not Found

The request filtering module is configured to deny a request where the query string is too long.

And that's because the URL has come out as:

http://localhost:53744/Account/Login?ReturnUrl=%2FAccount%2FLogin%3FReturnUrl%3D%252FAccount%252FLogin%253FReturnUrl%253D%25252FAccount%25252FLogin%25253FReturnUrl%25253D%2525252FAccount%2525252FLogin%2525253FReturnUrl%2525253D%252525252FAccount%252525252FLogin%252525253FReturnUrl%252525253D%25252525252FAccount%25252525252FLogin%25252525253FReturnUrl%25252525253D%2525252525252FAccount%2525252525252FLogin%2525252525253FReturnUrl%2525252525253D%252525252525252FAccount%252525252525252FLogin%252525252525253FReturnUrl%252525252525253D%25252525252525252FAccount%25252525252525252FLogin%25252525252525253FReturnUrl%25252525252525253D%2525252525252525252FAccount%2525252525252525252FLogin%2525252525252525253FReturnUrl%2525252525252525253D%252525252525252525252FAccount%252525252525252525252FLogin%252525252525252525253FReturnUrl%252525252525252525253D%25252525252525252525252FAccount%25252525252525252525252FLogin%25252525252525252525253FReturnUrl%25252525252525252525253D%2525252525252525252525252FAccount%2525252525252525252525252FLogin%2525252525252525252525253FReturnUrl%2525252525252525252525253D%252525252525252525252525252FAccount%252525252525252525252525252FLogin%252525252525252525252525253FReturnUrl%252525252525252525252525253D%25252525252525252525252525252FAccount%25252525252525252525252525252FLogin%25252525252525252525252525253FReturnUrl%25252525252525252525252525253D%2525252525252525252525252525252FAccount%2525252525252525252525252525252FLogin%2525252525252525252525252525253FReturnUrl%2525252525252525252525252525253D%252525252525252525252525252525252FAccount%252525252525252525252525252525252FLogin%252525252525252525252525252525253FReturnUrl%252525252525252525252525252525253D%25252525252525252525252525252525252FAccount%25252525252525252525252525252525252FLogin%25252525252525252525252525252525253FReturnUrl%25252525252525252525252525252525253D%2525252525252525252525252525252525252FAccount%2525252525252525252525252525252525252FLogin%2525252525252525252525252525252525253FReturnUrl%2525252525252525252525252525252525253D%252525252525252525252525252525252525252F

Any ideas what i have done wrong?

I tried using this as a header for a view but it returns an empty string. In the Razor layout, I have something like:

@model IEnumerable<MVCApp.Models.Model>
<h2>@Html.DisplayNameForModel()</h2>

Do I need to set something on the model definition itself? I tried a data annotation [Display(Name="Model Name")] but it is a build error:

Attribute 'Display' is not valid on this declaration type. It is only valid on 'method, property, indexer, field, param' declarations.

The documentation DisplayNameExtensions.DisplayNameForModel Method is terse. The syntax calls for a parameter, but says:

No overload for method 'DisplayNameForModel' takes 1 arguments

As the Usage section says "When you use instance method syntax to call this method, omit the first parameter"

So, how do I use this method to return something?

I am currently trying to do a redirect from a login page, back to the asked operation. Here are my two controller methods:

private BrewMasterContext UR = new BrewMasterContext();
[HttpGet, AllowAnonymous]
public ActionResult Connexion(string ReturnUrl)
{
    ViewBag.url = ReturnUrl;
    return View();
}

[HttpPost, AllowAnonymous]
public ActionResult Connexion(UtilisateursConnexion UC, string ReturnUrl)
{
    Utilisateur p =null;
    UC.MDP=Utilisateur.CrypterMDPSHA256(UC.MDP);
    if (ModelState.IsValid)
    {

        IQueryable<Utilisateur> u = UR.Utilisateurs.Where(f => f.NomUtilisateur == UC.NomUtilisateur && f.MDP ==UC.MDP);
        foreach (Utilisateur user in u)
        {
            p = user;
        }
        FormsAuthentication.SetAuthCookie(p.NomUtilisateur, UC.ConnPersistante);

        Session["AdminBool"] = p.Admin;
        return RedirectToAction("ChangerLangue", "Home", new { Langue = p.Langue, returnurl = ReturnUrl });
    }
    return View(UC);
}

Where BrewMasterContext is the database. Question: How can make use of the ViewBag.url element in the corresponding view?

I am trying to make a menu that will appear like this:

LOGS | BULLETIN | LOCATIONS | DIRECTORY | POLICIES

Note that the last item does not have a | after it.

This is my code now:

    <ul>
        @{
            var homeNode = Model.Content.AncestorOrSelf("Homepage");
        }
        @foreach (var node in homeNode.Children.Where("Visible"))
        {
            <li>
                <a href="@node.Url">@node.AsDynamic().Name</a> |
            </li>
        }
    </ul>

Which renders this:

LOGS | BULLETIN | LOCATIONS | DIRECTORY | POLICIES |

What can I add to the code so that it adds | after each node name EXCEPT the last one?

I have this table and shows values from server. How I can with jquery add new row in this table if I want to sent values from table to Server

<table id="Products" class="Products">
    <tr>
        <th>ProductId</th>
        <th>Productname</th>
        <th>Quantity</th>
        <th>UnitPrice</th>
    </tr>

    @for (int i = 0; i < Model.NorthOrderDetails.Count; i++)
    {
        <tr>
            @Html.HiddenFor(m => m.NorthOrderDetails[i].ProductID)
            @Html.HiddenFor(m => m.NorthOrderDetails[i].ProductName)
            <td>@Html.DisplayFor(m => m.NorthOrderDetails[i].ProductID)</td>

            <td>@Html.DisplayFor(m => m.NorthOrderDetails[i].ProductName)</td>

            <td><input type="hidden" name="NorthOrderDetails.Index" value="@i" /> </td>

            <td> @Html.TextBoxFor(m => m.NorthOrderDetails[i].Quantity) </td>

            <td> @Html.TextBoxFor(m => m.NorthOrderDetails[i].UnitPrice, String.Format("{0}", Model.NorthOrderDetails[i].UnitPrice))</td>
            <td>
                <button type="button" class="delete" data-id="@Model.NorthOrderDetails[i].ProductID">Delete</button></td>
        </tr>
    }
</table>    

After deciding to move everything to Owin, i chose NancyFx to handle my routes, views, etc... however Nancy Razor doesn't seem to work well because i have some weird issues like

  1. Cannot Resolve Symbol 'X'.
  2. Cannot Resolve Section 'X'.

Here is a picture showing what's going on inside visual studio...

enter image description here

And here is my web.config file

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="razor" type="Nancy.ViewEngines.Razor.RazorConfigurationSection, Nancy.ViewEngines.Razor" />
    </sectionGroup>
  </configSections>
  <!--
    For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.

    The following attributes can be set on the <httpRuntime> tag.
      <system.Web>
        <httpRuntime targetFramework="4.5.1" />
      </system.Web>
  -->
  <system.web>
    <compilation debug="true" targetFramework="4.5.1">

      <buildProviders>
        <add extension=".cshtml" type="Nancy.ViewEngines.Razor.BuildProviders.NancyCSharpRazorBuildProvider, Nancy.ViewEngines.Razor.BuildProviders" />
        <add extension=".vbhtml" type="Nancy.ViewEngines.Razor.BuildProviders.NancyVisualBasicRazorBuildProvider, Nancy.ViewEngines.Razor.BuildProviders" />
      </buildProviders>
    </compilation>
    <httpRuntime targetFramework="4.5.1" />
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

  <system.web.webPages.razor>
    <pages pageBaseType="Nancy.ViewEngines.Razor.NancyRazorViewBase">
      <namespaces>
        <add namespace="Rockariam.Core.Controllers"/>
        <add namespace="Rockariam.Core.Libraries"/>
        <add namespace="Rockariam.Core.Models"/>
        <add namespace="System"/>
        <add namespace="System.Linq"/>
      </namespaces>
    </pages>
  </system.web.webPages.razor>

  <appSettings>
    <add key="webPages:Enabled" value="false" />
  </appSettings>
</configuration>

I have menu and using this I'm rendering partial view in my index page

@Ajax.ActionLink("week I", "firstWeekWinners", new
{

}, new AjaxOptions()
{
    HttpMethod = "GET",
    UpdateTargetId = "weeWinnersDIv",
    InsertionMode = InsertionMode.Replace
}, new { @class = "weekDays wactive" })

and there's partial view controller:

 public PartialViewResult firstWeekWinners()
    {
        ViewBag.laptopWinners = db.firstWeekLaptopWinner().ToList();
        ViewBag.tabWinners = db.firstWeekGalaxyWinner().ToList();
        ViewBag.ipodWinners = db.firstWeekIpodWinner().ToList();
        ViewBag.headPhonesWinners = db.firstWeekHeadPhonesWinner().ToList();
        ViewBag.kingstonWinners = db.firstWeekkingstonUsbWinner().ToList();

        return PartialView();
    }

and partial view:

  @if (ViewBag.laptopWinners != null)
{
    <div class="winnersPrizeOverflow">
        <div class="winnersPrizePic"></div>
        <div class="winnersAllprizeLeft"><p>12</p></div>
    </div>
    foreach (var q in ViewBag.laptopWinners)
    {
        <span>@q.firstName</span>
        <br />
        <span>@q.lastName</span>
        <br />
        <span>@q.fbId</span>
        <br />
        <span>@q.sumOfBids</span>
        <br />
    }
}

If I'll click to this ajax.actionlink it renders this view but without this if I'll put @Html.Partial("firstWeekWinners") it doesn't goes in controller to retrieve my data. How can I improve that?

And my endless problems from server created controls continue.

I am have users that in different groups and each group has different user information. I am creating a page to manage users in a group using a Telerik RadGrid. Because of the unknown nature of the grid columns I am creating the grid on completely on the server. You cannot have a grid defined in the aspx page and add columns in the server aspx.cs code, all kinds of things break like sorting, filters and getting extra text

A feature I need is to output excel files with the grid's data. The problem, how do I reference the grid in server calls backs. If you look at Telerik Grid Export to Excel there is a button callback that changes grid values on the server and initiates the excel export on the grid control in ImageButton_Click. In my case RadGrid1 is created in the server in the Page_Init and added to an asp:PlaceHolder. The grid works fine.

Is there any way to reference a server added control back in the server aspx.cs code. Putting the control id will not compile.

Thanks, George

I need font finding web application script like whatthefont. This script must can,

  • identify Letters on uploaded image(or url)
  • match similar font that already in database.

wikipedia says "MyFonts has not provided details of the algorithms behind WhatTheFont."

Kevin Woodward is the creator of WhatTheFont. He developed the font-identification algorithm

How do I get whatthefont font detection script or similar script to http://myfonts.com/WhatTheFont/ ?

Ok, I have gone through almost every question, PHP Manual and post around this issue all over the internet. Nothing seems to help.

I'm working on a project that needs me to authenticate (or at least be able to lookup the UID for) different users in my organisation on an Active Directory. For connecting and authenticating, they have provided me with a dll file which has the functions necessary to authenticate. I need to use this dll file and the functions within to get my application working.

Below are the different things I have tried so far along with errors for each.

  1. Use dl() to load the DLL.

I tried using

dl('filename.dll');

and got the error

Call to undefined function dl() in C:\xampp\htdocs\OOP_curater\index.php on line 16

After looking around I came across this and this I realized it's no more supported.

I then tried placing the dll in C:\xampp\php\ext and adding an extention line to php.ini. (Just for the heck of it) restarting php gave me an error message saying it's not a valid PHP extention.

  1. Tried using COM()

I then tried using

$action = new COM("ProjectName.FunctionName") or die ("Could not initialise MS Word object."); 

and got the following error

Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object `ProjectName.FunctionName': Invalid syntax ' in C:\xampp\htdocs\OOP_curater\index.php:3 Stack trace: #0 C:\xampp\htdocs\OOP_curater\index.php(3): com->com('FBA_Provider1.a...') #1 {main} thrown in C:\xampp\htdocs\OOP_curater\index.php on line 3

Looking around got me to links similar to this. I realized I need to register the DLL so tried

regsvr32 C:\xampp\htdocs\OOP_curater\filename.dll

and got the error

DllRegisterServer entry point was not found

I then tried

regsvr32 /i /n C:\xampp\htdocs\OOP_curater\filename.dll

and got a "DLL Install was not found" error.

I must admit, I'm still not sure if I got the (Projectname.FunctionName) part right, i really could not understand most of the documentation around this topic.

  1. Tried using DOTNET()

I then tried the following code

$comobj = new DOTNET("projectname", "projectname.function");

and got this error

Fatal error: Uncaught exception 'com_exception' with message 'Failed to instantiate .Net object [CreateInstance] [0x80070002] The system cannot find the file specified. ' in C:\xampp\htdocs\OOP_curater\index.php:21 Stack trace: #0 C:\xampp\htdocs\OOP_curater\index.php(21): dotnet->dotnet('ProjectName', 'Function') #1 {main} thrown in C:\xampp\htdocs\OOP_curater\index.php on line 21

I now have the following questions with regards to loading a DLL for PHP

What is the best way to load a DLL where:

a. It is not really a PHP function

b. The source is not available

c. It cannot be registered (assuming due to the errors above)

d. It cannot be recompiled to be a PHP Extension / Register able

Few Things to Note

  1. The setup is currently on XXAMP for development and testing.
  2. I do not have admin rights, but can arrange for it if necessary.
  3. Production environment would be on a windows server running IIS.

I have very little knowledge in .net and Active Directory which is why I find this even tougher to handle. Also given the length of the question, hope I didn't miss out on anything important. Do let me know if you need more info.

EDIT

I was able to decompile the DLL using Reflector, and now have the source code and access to Microsoft Visual Studio for Applications 2.0. Incase you need me to make changed to the DLL itself.

Also I tried building it with the "make visible to com" option checked but still got the same error with regsvr 32 and regasm.

I want to search the Details using date, it will not work, but by searching name it can be work.

My controller code:

public ActionResult ProjectReport(string searchstring)
{
    using (db)
    {
       // var v = db.Projects.ToList();
        var Projects = from p in db.Projects
                       select p;
        if (!String.IsNullOrEmpty(searchstring))
        {
            Projects = Projects.Where(p => p.ProjectTitle.Contains(searchstring));
        }
        var dateFilter = Convert.ToString(Request["sSearch_3"]);
        if (dateFilter.Contains('~'))
        {
            //Split date range filters with ~
            DateTime = dateFilter.Split('~')[0] == "" ?
            DateTime.MinValue : Convert.ToDateTime(dateFilter.Split('~')[0]);

        }
        return View(Projects.ToList());
    }
}

Here I've came across using WCF service and it's RESTclient in same application. But I have a question that, is there any way to restrict the url parameter of Ajax to view in browser's Page Source or console f12?

Here is simple Example:

<script type="text/javascript">
    var D = document;

    //get data function
    $(D).ready(getyearData());
    function getyearData() {
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: 'Service1.svc/GetYears',
            dataType: "json",
            //async: false,
            success: function (data) {
                var a = data.GetYearsResult.Data;
                var response = $.parseJSON(a);
                $('#ddlYears').empty();
                var ddl = D.getElementById('ddlYears');
                var opt = D.createElement("option");
                opt.text = '--Select--';
                opt.value = 0;
                ddl.options.add(opt);
                for (i = 0; i < response.length; i++) {
                    opt = D.createElement("option");
                    opt.text = response[i]['holiday_date'];
                    opt.value = response[i]['holiday_date'];
                    ddl.options.add(opt);
                }
            },
            error: function (data) {
                alert('Error Occured');
            }
        });
    }
</script>

And, this function is able to view in Browser using ways mentioned above. Any possible way to hide the script tags or at least url in Ajax call, in ASP.NET, JQuery?

I have an asp.net web forms application it uses EF for all database activities. When page loads I have to fetch lot of data from different tables. I have a DataAccessor class where I am having a member variable of Entity Framework DbContext (MyDBEntities). See class definition below.

public class DataAccessor
{
    public static DataAccessor Instance = new DataAccessor();
    private MyDBEntities dbEntities = new MyDBEntities();

    private DataAccessor() 
    {
    }

    public FetchTable_1_Data()
    {
        return dbEntities.Table1.Where( x => x.Id = something).List();
    }

    public FetchTable_2_Data()
    {
         return dbEntities.Table2.Where( x => x.Id = something).List();
    }

    public FetchTable_n_Data()
    {
         return dbEntities.TableN.Where( x => x.Id = something).List();
    }

}

Using data accessor as below in page load

Page_Load()
{
   Repeater1.DataSource = DataAccessor.Instance.FetchTable_1_Data();
   Repeater1.DataBind();

   Repeater2.DataSource = DataAccessor.Instance.FetchTable_2_Data();
   Repeater2.DataBind();
}

My Questions are,

  1. When DB connection is getting open in my case
  2. When DB connection getting closed?
  3. Do I need to use using(MyDBEntities dbEntities = new MyDBEntities()) instead of using member variable
  4. If i would need to use as question #3, do I need to open connection using "using" statement in each fetch methods?

My database connection is broken sometimes and system performance is getting degrade, i suspect my usage of EF. Can someone advice me how to use EF?

Some more questions,

  1. How connection pooling is working with EF?

    connectionString="metadata=res:///ReviewsDb.csdl|res:///ReviewsDb.ssdl|res://*/MyDb.msl;provider=System.Data.SqlClient;provider connection string="data source=SERVER;initial catalog=MyDB;persist security info=True;user id=sa;password=mypwd;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />

  2. I am using above connection string, do I have connection pool with above connection string?

  3. How can I configure connection in EF

Appreciate any help on these questions. thank you friends