I have a view model having 2 properties: one is a list of items class objects and the other one is an object of order class. I want to show the sum of the price calculated from items' list in order.price

Here is view model:

public class PlaceOrderViewModel
{
    public Orders Order { get; set; }
    public List<Items> Items { get; set; }
}

Here is items model:

public class Items
{
    public long Id { get; set; }
    public long OrderId { get; set; }
    public int ItemType { get; set; }
    public string Detail { get; set; }
    public int ItemsCount { get; set; }
    public int Price { get; set; }
}

I am looking for something like this,

@Html.DisplayFor(model => model.Order.Price, new { Value = @Model.Items.Sum(s => s.Price)})

I did try this but this doesn't work for me.

I want to bind the sum value with the order.price property. Any help?

The default highlight-settings render @{ } with a yellow background which looks like a eye-sore if the dark theme is applied in Visual Studio.

I am trying to restrict duplicate entry to an XML file and below is the XML file.

<?xml version="1.0" standalone="yes"?>
<Info>
<Details>
<ID>Ryan</ID>
</Details>
<Details>
<ID>Danny</ID>
</Details>
</Info>

Now if I try to add Ryan or Danny again to the ID I should alert like user name already exists.

I'm using the below code and it doesn't work. strName is a string and has username value to be added. Can anyone provide suggestions?

XDocument xDoc = XDocument.Load(Server.MapPath("~/Info.xml"));
bool userExistsAlready = xDoc.Descendants("Details").Any(x => (string)x.Attribute("ID") == strName);
if (userExistsAlready)
{
    //alert
}

Return datatable or dataset in json format in wcf web service in c#

This is my code:

[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, 
           RequestFormat = WebMessageFormat.Json, 
           BodyStyle = WebMessageBodyStyle.Wrapped, 
           UriTemplate = "DoWork")]
public string DoWork()
{
        DataSet ds = new DataSet();

        DataTable dtStatus = new DataTable("Status");
        dtStatus.Columns.Add("status");
        dtStatus.Columns.Add("message");
        DataRow dr = dtStatus.NewRow();
        dr["status"] = "true";
        dr["message"] = "Logged in Successfully.";
        dtStatus.Rows.Add(dr);

        ds.Tables.Add(dtStatus);

        DataTable dtData = new DataTable("data");
        dtData.Columns.Add("ID");
        dtData.Columns.Add("email");
        dtData.Columns.Add("Name");
        DataRow drData = dtData.NewRow();
        drData["ID"] = "1";
        drData["email"] = "test@test.com";
        drData["Name"] = "Test";
        dtData.Rows.Add(drData);

        ds.Tables.Add(dtData);

        return JsonConvert.SerializeObject(ds);
}

Result should be this JSON data:

{

data:    {
       " email" : "rohit@gmail.com",
        "Name": 3,
        "ID" : 5
    },

 "message": "Logged in Successfully.";
    "status" : true
}

I'm a beginner. I started to study HTML, CSS and JAVASCRIPT just some months ago, by myself. Now I'd like to learn something about the server side and I saw a lot of articles about PHP, ASP.NET, Python, AJAX, JSON, MySQL, etc. Someone acclaims this, someone acclaims that and I'm not able to take a choose between those technologies, my ideas are totally confused! I need a specific suggestions in agreement with my future projects: I want to become a front-end/back-end developer and, as I said before, I'm studying Javascript right now. I'd like to create user interface for applications(customizations, profile editing,... ) that need a database or e-commerce websites. I work with Windows, I don't like Apple at all! I'm sorry if I'm not so precise about explaining my problem, but I know I still have to learn a lot of things! Please, help me to do that! Thanks

Trying to set sql server from a class in asp:sqldatasource tag:

Public staticSqlConnection getConnection()
{
      SqlConnection conn - new SqlConnection();
...
}

This function is tested in C# code and it works 100%. Now I'm trying to use it in an asp:SqlDataSource:

<asp:SqlDataSource runat="server" ID="sqlDBConnection"
ConnectionString="<%# inProcessInventory.DataTools.getConnection().ConnectionString %>"

I receive:

The ConnectionString property has not been initialized

Any suggestion?

I am a beginner in the MVC, Just learning now linq. I want to get the lowest value of the price column lines that meet the condition name = scott.

my controller:

public ActionResult WherePriceMin()
{
    var products = from p in repository.Products
                   where p.Name == "scott"
                   group p by p.Price into p
                   select new
                   {
                       scottMin = p.Min()
                   };

    return View(products);
}

my view

@model IEnumerable<BawimySieLinq.Domain.Entities.Product>

@{
    ViewBag.Title = "Products";
}
<h2>
    Show All
</h2>
<div>
    @Html.Partial("LinqLinks")
</div>
<div>
    @Html.Partial("ProductSummary")
</div>

my partial view

@model IEnumerable<BawimySieLinq.Domain.Entities.Product>

<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Description)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Category)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Price)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Quantity)
        </th>
        <th></th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Description)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Category)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Price)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Quantity)
            </td>
        </tr>
    }

</table>

I get an error:

The model item passed into the dictionary is of type 'System.Linq.Enumerable+WhereSelectEnumerableIterator2[System.Linq.IGrouping2[System.Decimal,BawimySieLinq.Domain.Entities.Product],<>f__AnonymousType11[BawimySieLinq.Domain.Entities.Product]]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[BawimySieLinq.Domain.Entities.Product]'.

 protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
    {

        Recaptcha.RecaptchaControl mycaptcha = (Recaptcha.RecaptchaControl)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("RecaptchaControl1");
        mycaptcha.Validate();
        Boolean answer = mycaptcha.IsValid;
        if (answer == false)
        {
            ((CancelEventArgs)e).Cancel = true;
        }
    }

Hi above is my code for Validating Google Recapture, i am using a CreateUserWizard form on Visual Studio.

the code is fine until i run it and an error appears stating

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

Additional information: Object reference not set to an instance of an object.

for the line mycaptcha.Validate();

im not sure hwo to fix it.

I have a WPF client application, and an ASP.NET WebApi 2.2 server application. The latter also hosts an Authorisation Server, and issues a bearer token to the user on successful login. This is also where the user's claims are added to their Identity object, and are thus included in the bearer token issued via a response header.

If I wanted to limit the user's choice of Branches to work with, would I add one claim for each branch included or excluded from his permitted Branches, or do I create a special claim type, inherited from IdentityUserClaim, that is more specific to this application, and encapsulates its own list of Branches, in the one claim? The latter seems to me better OOD and adheres more to the Single Responsibility Principal.

I have an infragistics web tab (Ultrawebtab) and i have a panel which i set visible false in designer.I want to display panel content only in one of the tab and clear in rest of the tab.I can do it by enabling autopostback true managing in tabclick event .But i dont iwant it since it will refresh the page everytime when i click the tabs.How to do it in different way like mouse over event or any other events in asp.net

<igtab UltraWebTab id="ulTab"><Tabs/><igtab>

So I'm just working on customizing some views with some controls that will allow the users to narrow down the results we would expect on the page, since we're expecting a great deal of information.

My intellisense is broken in VS2015, so I'm stumbling around in the dark a bit.

So I've populated a couple dropdown lists, month and year. Not the prettiest, but it works:

@Html.DropDownList("Month", new List<SelectListItem>
           {
                new SelectListItem { Text = "January", Value = "1"},
                new SelectListItem { Text = "February", Value = "2"},
                new SelectListItem { Text = "March", Value = "3"},
                new SelectListItem { Text = "April", Value = "4"},
                new SelectListItem { Text = "May", Value = "5"},
                new SelectListItem { Text = "June", Value = "6"},
                new SelectListItem { Text = "July", Value = "7"},
                new SelectListItem { Text = "August", Value = "8"},
                new SelectListItem { Text = "September", Value = "9"},
                new SelectListItem { Text = "October", Value = "10"},
                new SelectListItem { Text = "November", Value = "11"},
                new SelectListItem { Text = "December", Value = "12"}
           }, "Month")
           @Html.DropDownList("Year", new List<SelectListItem>
            {
                new SelectListItem { Text = Convert.ToString(DateTime.Now.Year - 1), Value = Convert.ToString(DateTime.Now.Year - 1)},
                new SelectListItem { Text = Convert.ToString(DateTime.Now.Year), Value = Convert.ToString(DateTime.Now.Year), Selected = true},
                new SelectListItem { Text = Convert.ToString(DateTime.Now.Year + 1), Value = Convert.ToString(DateTime.Now.Year + 1)},
            }, "Year")

Now when one of the dropdowns is changed, I'd like to send the dropdown selection from both controls to my Controller for this view, with the contents of the DD list. From there I can reload the page. The MSDN documentation is unclear, as the only constructor for DropDownList has no parameters, so I'm unclear as to where event driven stuff should go.

So I'm working with asp.net razor. The C# docs themselves are fine, but when it comes to the razor syntax, I'm finding myself totally lost.

The best MS documentation I've been able to find is this crappy page: https://docs.asp.net/en/latest/mvc/views/razor.html

Is there actually a complete API reference somewhere?

Unfortunately I encounter some problems with my project and it would be really nice to get some help. What I am tryng to achieve: Setting up Nginx 1.10.1 to run an ASP.NET (.NET framework 4.5) MVC5 with Razor project on Ubuntu 16.04 LTS using the mono-fastcgi-server4.

My Nginx configuration is as follows:

server {
    listen 80;
    server_name <my_domain_name_is_here>;

    location / {
            root /var/www/project/Views/Home;
            index Index.cshtml;
            fastcgi_index /;
            fastcgi_pass 127.0.0.1:9000;
            include /etc/nginx/fastcgi_params;
    }
}

I added the following lines into the /etc/nginx/fastcgi_params file:

fastcgi_param   PATH_INFO               "";
fastcgi_param   SCRIPT_FILENAME         $document_root$fastcgi_script_name;

I use the following command to start the fastcgi server: fastcgi-mono-server4 /applications=/:/var/www/project/Views/Home /socket=tcp:127.0.0.1:9000

When I visit the website, I get the following error (which looks like a ASP.NET generated error?):Runtime Error . If i change the fastcgi_index parameter into: fastcgi_index Index.cshtml; the website returns a 'download' file with no file type containing the source code of the Index.cshtml file.

A lot of tutorials out there, are all about .aspx files, so I created a Defaults.aspx file which contains the following content:

<%@ Page AutoEventWireup="true" Language="C#" ContentType="text/plain" %>

<script runat="server">

  void Page_Load(object sender, EventArgs e)
  {
    this.Response.Write("Hello World!");
 }

</script>

After changing my /etc/nginx/sites-avaiable/application.conf file and restarting the Nginx webserver the website prompted the 'Hello World'. I'm not using aspx but cshtml instead, but you can say that the fastcgi is working right, because aspx does also have to be compiled.

So does anyone have any idea how to fix this and get my project running? Fyi: The project is running fine in the MonoDevelop Desktop client (no errors).

I know this might sound kinda stupid, but is it possible to set buttons, textbox etc etc.. in toolbox in visual studio 2015. but making the design in CSS?

I know you can give the same button the exact style form with CssClass="yourclass". But was thinking for this, and google didn't help me much.

So I'm working with asp.net razor. The C# docs themselves are fine, but when it comes to the razor syntax, I'm finding myself totally lost.

The best MS documentation I've been able to find is this crappy page: https://docs.asp.net/en/latest/mvc/views/razor.html

Is there actually a complete API reference somewhere?

I'm currently having a problem with optimistic concurrency in my ASP.NET MVC application.

Essentially, this following controller works fine when called upon once. However, I have a page that is made to modify residents in six different groups at the same time. This is where the problem occurs. Basically, I post up the list of residents one at a time for each list so there are essentially six concurrent ajax calls that hit the server at the same time. (This may be what I need to change, but I am not sure!)

The javascript ajax call posts up the id of the group along with a list of the resident IDs. The residents are then added to the groups references. I have been looking into refreshing the state, but this isn't working as it seems only one of the six groups is updated. I have tried also letting the client win. I really just need some guidance and tips on resolving this issue!

Here is my current code in my controller:

var group = _context.TherapyGroups.Include(r => r.Residents)
                                              .Where(x => x.ID.ToString() == groupid).FirstOrDefault();
            if(group == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            group.Residents.Clear();
            foreach(var id in residents)
            {
                var resident = _context.Residents.Where(x => x.ID.ToString() == id).FirstOrDefault();
                if(resident == null)
                {
                    throw new HttpResponseException(HttpStatusCode.NotFound);
                }
                group.Residents.Add(resident);
            }
            bool saveFailed;
            do
            {
                saveFailed = false;
                try
                {

                    _context.SaveChanges();
                }
                catch (DbUpdateException e)
                {
                    saveFailed = true;
                    ((IObjectContextAdapter)_context).ObjectContext.Refresh(RefreshMode.StoreWins, _context.Residents);
                }
            } while (saveFailed);

I'm' trying to execute a post build event that builds a nuget package based on a .nuspec file. I'm using Visual Studio 2013. My post build event command line is:

nuget pack $(ProjectPath) -Symbols -Properties Configuration=$(ConfigurationName) -IncludeReferencedProjects

When I build my project, I get the following error:

The command "nuget pack C:\Users\user\Documebts\Code\BookProject\BookProject.Nuget\
BookProject.Nuget.csproj -Symbols -Properties Configuration=Debug 
-IncludeReferencedProjects" exited with code 1.

I'm not sure what's going on - I changed the Visual Studio build output to Diagnostic and found this:

>Using 'BookProject.nuspec' for metadata. (TaskId:44)
>Access to the path 'C:\BookProject.1.0.3.4.nupkg' is denied. (TaskId:44)
>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(4714,5): error MSB3073: The command "nuget pack C:\Users\user\Documebts\Code\BookProject\BookProject.Nuget\  BookProject.Nuget.csproj -Symbols -Properties Configuration=Debug -IncludeReferencedProjects" exited with code 1." exited with code 1.
>Done executing task "Exec" -- FAILED. (TaskId:44)
>Done building target "PostBuildEvent" in project "Miw.Mshdf.Net.Nuget.csproj" -- FAILED.: (TargetId:72)

If I open up a command prompt and type in the post build event command, it works fine and builds the nuget package without any problems. Any ideas?

I'm converting an existing web app from net framework to net core - but having a few troubles.

  1. How to replace usage of WebImage

  2. How to get CurrentCulture - used for Localization

Thanks in advance

/Søren

I have two tables.

Title and Comment two tables bind each other.

Below query the title according to last comment order by. But at the same time I get data if title ok==true . How can I add the Title Ok== True.

var bb = tr.Basliklar
          .OrderByDescending(
             b => b.Yorumlar.Any(y => y.Ok == true) 
             ? 
             b.Yorumlar.Where(y => y.Ok == true).Max(y => y.Tarih) 
             : 
             b.Tarih
           )
          .FirstOrDefault();

I do have two page. One is Default.aspx and another one is DetailView.aspx. What I want to do is that I want to redirect page from Default.aspx to detailView.aspx using ajax call and I want to pass one value also. I have done something but it is not calling function that is defined into class.

I am calling this function from Default.aspx webfile

$.ajax({
       type: 'POST',
                url: 'DetailView.aspx/Test',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: '{pid:' + result + '}',
                success: function (data) {

                }
            });

this is class file of DetailView.aspx

[WebMethod(EnableSession = true)]
public static string Test(string pid)
{
    return " ";
}

I was debugging this function but it is not calling this function at all when ajax being called.

In old sweet Web Forms times, when we make change on code behind, once we hit the application, it was compiling on the fly and running new changed code.

For Web Apps and MVC, when I add a new controller or change something on business logic, I have to always build app on VS 2015 manually and go back to browser and test again. But many times I keep forgetting building till I see yellow error screen.

Is there any way to kick build if there is code change and if I hit the website first time like Web Forms? I would not prefer to build on save since I am a ctrl + S freak, and keep pressing that combo on every other second.