I have the following jquery script in a Razor view with layout set to the null.

<script type="text/javascript">
        jQuery(document).ready(function () {

            $('#shareapp').click(function () {
                check_if_fb_is_defined();
            });
            window.fbactivity_id = '@Model.Id';
            window.fbactivity_name = 'your-hollywood-movie';
            window.wallpost_name = 'How would be your hollywood movie poster look like ?';
            window.wallpost_picture = '@ViewBag.ImageURL';
            window.wallpost_description = 'How would be your hollywood movie poster look like?';
            window.wallpost_link = '@Html.Raw(string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority,Url.Action("campaign_result", "facebook", new { @resultid = Model.Id, @imgURL = ViewBag.ImageURL  })))';
            window.wallpost_caption = 'Ozhay';
            window.tags = 'Naser';
            function check_if_fb_is_defined() {
                if (typeof (FB) === 'undefined') {
                    fbsharer();
                } else {
                    PostShare('@Html.Raw(string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority,Url.Action("campaign_result", "facebook", new { @resultid = Model.Id, @imgURL = ViewBag.ImageURL})))';
                }
            }
}
</script>

I have added Jquery script file to the view but for whatever reason When I click on a link that has shareapp id nothing happens. This is a bit strange to me where sometimes before it worked. your thoughts about this?

I deleted temporary asp.net folder before mspatching to the server by mistake. After ms patching we are unable to access the application. We are getting server error on application. How can we solve this problem?

how to compare two string in asp.net means easily we can compare two string like==>

if(Path.GetExtension(fileupload1.FileName).ToLower() == ".png" || Path.GetExtension(fileupload1.FileName).ToLower() == ".jpeg")

but is there any way to do this like i wnats to do something like that=>

if((Path.GetExtension(fileupload1.FileName).ToLower()) == ".png" || ".jpeg")

but it gives me error.can anybody help me?

I have problem with removing values from my database. When I try to remove data from table Stuffs, which are connect by Foreign key with table Orders it show me how to fix nullreferenceexception was unhandled error message, but if I take breakpoint on row "db.Stuffs.Remove(stuff);" and try to remove the same value again it works. How can I fix it?

  [HttpPost, ActionName("Delete")]
    [ValidateAntiForgeryToken]
    public ActionResult DeleteConfirmed(int id)
    {
       // var order = db.Orders.FirstOrDefault(d => d.StuffId == id);
        Stuff stuff = db.Stuffs.Find(id);
            db.Stuffs.Remove(stuff);
            db.SaveChanges();
        return RedirectToAction("Index");
    }

I have here the following code.It works well, arrows are shown only when user click on Parent category.I want arrows to be shown on parent category also if user don't click on that category which has child elements.I cannot see here where I make a mistake.

Here's a snippet:

$('.mainNav li:has(ul)').addClass('has-child');
.mainNav li.has-child>a:after {
  color: #444;
  content: ' ▾';
}
<ul class="mainNav">
  <li class="child">
    <a href="#category1">Category 1</a>
    <ul class="child">
      <li>Child 1.1</li>
      <li>Child 1.2</li>
      <li>Child 1.3</li>
    </ul>
  </li>
  <li class="child">
    <a href="#category1">Category 2</a>
  </li>
  <li class="child">
    <a href="#category1">Category 3</a>
    <ul class="child">
      <li>Child 3.1</li>
      <li>Child 3.2</li>
    </ul>
  </li>
</ul>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Here's my MVC code:

   <style>
    .mainNav li.has-child > a:after {
        color: #444;
        content: ' ▾';
    }
</style>
<script>      
    $('.mainNav li:has(ul)').addClass('has-child');          
</script>

   <ul class="mainNav">
    <li class="child">
  <a href="@Url.RouteUrl("Category", new {SeName =    category.SeName})">@category.Name</a>
      @{
            if (category.Id == Model.CurrentCategoryId ||
                category.SubCategories.Count(BreadCrumbContainsCurrentCategoryId) > 0)
            {
                if (category.SubCategories.Count > 0)
                {
                    <ul class="child">
                        @foreach (var subCategory in category.SubCategories)
                        {
                            <li> @RenderCategoryLine(subCategory)</li>
                        }
                    </ul>
                }
            }
        }
    </li>
</ul>

There is a Grid with data which is loaded in View on selecting Edit button of a record in a row i was suppose to load a Bootstrap - Modal with selected data . Is this possible to achieve I tried of many tutorial but no use Help me in doing it. I Am new to Bootstrap and jQuery.

Grid Image

On clicking Edit button it has to displayed in a Model for performing operation.

I have a Web Service application written in C#. I want it to handle a basic request, namely, from a form, it should get file name and file content and save it to Web Service's working directory. The code is:

[WebMethod]
    public void PutFile(byte[] buffer, string filename)
    {
        BinaryWriter binWriter = new BinaryWriter(File.Open(Server.MapPath(filename), FileMode.CreateNew, FileAccess.ReadWrite));
        binWriter.Write(buffer);
        binWriter.Close();
    }

When I invoke it by running xsp in the directory of .asmx file, I can use other Web Services, such as add two numbers, etc. However when I invoke PutFile method, I get following error

500 - Internal Server Error System.ArgumentException: WebChangeTypeFailed Parameter name: type ---> System.FormatException: Input string was not in a correct format.

And follows some function errors.

I am new for developing Web Service applications using .NET and I am not sure about the cause of this problem. I've looked at web.config file and I didn't notice something strange. web.config file is:

    <?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation defaultLanguage="C#" debug="true">
      <assemblies>
        <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <add assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </assemblies>
    </compilation>
    <customErrors mode="RemoteOnly">
    </customErrors>
    <authentication mode="None">
    </authentication>
    <authorization>
      <allow users="*" />
    </authorization>
    <httpHandlers>
    </httpHandlers>
    <trace enabled="false" localOnly="true" pageOutput="false" requestLimit="10" traceMode="SortByTime" />
    <sessionState mode="InProc" cookieless="false" timeout="20" />
    <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
    <pages>
    </pages>
  </system.web>
</configuration>

Can anyone help ? Thanks.

Please how do I retrieve Data in a gridview in from form MySQL in an asp.net project data source.

Note:I used navicat lite GUI. Thanks.

I have a model named Order which has a property named Customer. The Customer is a complex object with id, name, balance, etc.

When passing the Order object to a view, the view can access the Customer object and its data as expected. However, when I post back to the Controller, the Order object is populated as expected, but the Customer object is null.

It would be nice if I could add a hidden field in the view for the Customer so it would be included in the post back, but I understand this works for single values not for complex types.

I suppose I could add all the Customer fields to the Order object, but before I do that, is there a way to include the complex object in the postback, or is there a better approach than consolidating the two objects into one by putting the individual Customer fields into the Order type?

This question already has an answer here:

I am using ExecuteScalar(). So It will return single column.

If the record is exist, It's not showing any error. If record is not found. It throws System.NullReferenceException on the following line

cmd.CommandText = "select top 1 UserID from [HQWebMatajer].[dbo].[SecurityUserDetails] where [UserID]=@UserID and [ReportName]='TotalSales';";
cmd.Parameters.AddWithValue("@UserID", ddlSecurityUser.SelectedValue);

con.Open();
string dataExist = null;
dataExist= cmd.ExecuteScalar().ToString(); // Error

I have developed a Web application using visual studio 2015,this ASP.NET MVC 4.5 application is published using FTP In Visual studio to a Machine running IIS server version 7, I don not have administrative rights to the machine hosting iis7 so i cant upgrade the iis or .net framework but can access the remote folder and path though FTP Client, error message I get on machine hosting iis when I edit the web.config I get the following errors on the machine hosting iis error 2 and further [error3][3]

I want to add a family which has many members and can have many houses. I am trying to make a form and submit the object family with collection of other objects. I have tried few things but I can only get one object to pass to controller and not the collection. What can i do?
should i make member and house partial views and render them in the view ??
Is there any way of doing this with collecting everything in JavaScript and then passing a whole family object to the controller?
I am using MVC 5 with Entity Framework. I am not able to solve this problem. Any help is appreciated.

here is an example of objects

public class family
{

    public int id { get; set; }
    public int familyname { get; set; }
    public List<member> members { get; set; }
    public List<house> houses { get; set; }
}

public class member
{
    public int id { get; set; }
    public string name { get; set; }
    public DateTime birthdate { get; set; }

    //foreign key
    public family Family { get; set; }
    public int FamilyID { get; set; }
}

public class house
{

    public int id { get; set; }
    public int number { get; set; }
    public string address { get; set; }
    //foreign key
    public family Family { get; set; }
    public int FamilyID { get; set; }
}

public class FamilyViewModel
{
   public family Family { get; set; }
    public member Member { get; set; }
    public house House { get; set;}
    public List<member> Members { get; set; } //??
    public List<house> Houses { get; set; } //??
}

View

@model WebApp.ViewModels.FamilyViewModel


@{
    ViewBag.Title = "New";
    Layout = "~/Views/Shared/_Layout.cshtml";
}


<h2>Family</h2>

@using (Html.BeginForm("Submit", "Family"))

{

<div class="form-group">
    @Html.LabelFor(m => m.Family.familyname)
    @Html.TextBoxFor(m => m.Family.familyname, new { @class = "form-control" })
</div>
<div id="member">
</div>
<div id="house">

</div>

Controller

    [HttpPost]
    public ActionResult Submit(FamilyViewModel CompleteFamily)
    {

        //What to do here?

        return View();
    }

I am trying to display a report viewer on an asp.net page. For some reason, this is what I get:

picture link

As you can see, the toolbars are not displaying properly.

I remember long time ago, writing a similar code in Visual Studio 2010, and had no problem. But now that I have this one on Visual Studio 2012, it just refuses to show properly.

I feel that this should have a quick solution but I am just not seeing it.

Any help would be appreciated.

Thanks

im trying to load the following Database structur

User -> UserTeamRelation -> Team -> Game

In this relation "Team" is already null when trying to access "user.Teams.Team".

I have the following Database structure

public class User : IdentityUser
{
    public User()
    {
        this.Id = Guid.NewGuid().ToString();
    }

    public virtual ICollection<TeamMember> Teams { get; set; }
}

public class Team
{
    public Team()
    {
        this.Id = Guid.NewGuid().ToString();
    }

    [Key]
    public string Id { get; set; }

    public virtual ICollection<TeamMember> Memberinos { get; set; }

    [Required]
    public virtual Game Game { get; set; }
}

public class TeamMember
{
    public TeamMember()
    {
        this.Id = Guid.NewGuid().ToString();
    }

    [Key]
    public string Id { get; set; }

    public virtual Team Team { get; set; }

    public virtual User Member { get; set; }
}

public class Game
{
    public Game()
    {
        this.Id = Guid.NewGuid().ToString();
    }

    [Key]
    public string Id { get; set; }

    public string Name { get; set; }
}

I tried the following code

using (var db = new ApplicationDbContext())
{
    var user = db.Users.FirstOrDefault(x => x.UserName.ToLower().Equals(username));
    if (user == null)
    {
        return new ResponseViewModel(false, "User nicht gefunden", null);
    }

    var teams = new List<Team>();
    foreach (var team in user.Teams)
    {
        teams.Add(new Team()
        {
            Description = team.Description,
            TeamName = team.Team.TeamName,
            GameName = team.Team.Game.Name
        });
    }
}

it reaches the foreach loop and finds the "Description" property. but when i try to access the team model, its null.

Any suggestion?

Kindly Help What should i do. My Theme is changed when page redirects Here is ASP.NET Code

<form id="form1" runat="server">
    <div id="dvLeft"></div>
    <div id="dvRight"></div>
    <div id="dvMiddle"></div>
    <div id="dvBottom">
        <asp:DropDownList ID="ddlTheme" runat="server" AutoPostBack="True">
            <asp:ListItem >FirstTheme</asp:ListItem>
            <asp:ListItem>SecondTheme</asp:ListItem>
            <asp:ListItem>ThirdTheme</asp:ListItem>
        </asp:DropDownList>
    </div>
</form>

And Here is C# Code:

protected override void OnPreInit(EventArgs e)
{
    if (Request["ddlTheme"] != null)
    {
        string theme = Request["ddlTheme"].ToString();
        Page.Theme = theme;
    }
    base.OnPreInit(e);
}

I have this table which contains of 3 renderOrderPropertyBlock.

<table align="center" class="wrapper header float-center">
    <tr>
        <td class="wrapper-inner background-color__yellow">
            <h5>Reservation</h5>
                @renderOrderPropertyBlock("", Model.Order.FirstName.ToString(), Model.Order2.FirstName.ToString());
                @renderOrderPropertyBlock("", Model.Order.LastName.ToString(), Model.Order2.LastName.ToString());
                @renderOrderPropertyBlock("", Model.Order.City.ToString(), Model.Order2.City.ToString());
        </td>
    </tr>
</table>

Each renderOrderPropertyBlockis calling a longer table that generates 3 columns, which is looking like this:

Example

But I need to have the text in 1 column like this:

Example

How can I print the renderOrderPropertyBlock right after eachother, instead of calling the long table after each renderOrderPropertyBlock?

ASP .NET Dynamically generate classes & compiles an assembly to the Temporary ASP.NET files.

I would like to be able to get information when this process happens. Ultimately, I would like to have an event that will fire the name of the source file and the generated class name + assembly so I could map between methods in the original source file and methods in the generated classes.

I'll appreciate your help.

I'm using a model that contains a List as a property. I'm populating this list with items I grab from SQL Server. I want the List to be hidden in the view and passed to the POST action. Later on I may want to add more items to this List with jQuery which makes an array unsuitable for expansion later on. Normally you would use

@Html.HiddenFor(model => model.MyList)

to accomplish this functionality, but for some reason the List in POST is always null.

Very simple question, anyone know why MVC behaves like this?

I am trying to route a request

/api/someName.xml?param1=123

I tried routing all requests to my default controller - MyController and it will route a call like:

http://localhost:54865/api/someName?param1=312.1232&param2=13.321

but I need not route a request like

http://localhost:54865/api/someName.xml?param1=312.1232&param2=13.321

I am not able to do that right now with the following Route map entry:

config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{*uri}",
                defaults: new { controller = "MyController"});

how can I allow endpoints with extension (someName.xml) to be routed?

Thanks

This works

@Html.Action("LiveBlogHeader", "Blog", new { liveMatchItemId = "12" })

I want to set hidden field's value in it. Something like this

@Html.Action("LiveBlogHeader", "Blog", new { liveMatchItemId =  @:document.getElementById('liveMatchItemId').value })

which apparently not working. Can you please help?

I have 2 models, Subjects and Grades

i want to create a dynamic view, with for each element in Subject, create a row in a table with subject name and 3 inputs for grades, and then fill the grades and passing to the controler for operations and storage on database.

i have this model

namespace CalculaNotas.Models
public class Materias
{

public int materiasId { get; set; }

[Required]
[MinLength(length: 5, ErrorMessage = "El nombre debe contener al menos 5 caracteres")]
[MaxLength(length: 20, ErrorMessage = "El nombre debe contener maximo 2 caracteres")]
[Index(IsUnique = true)]
public string nombre { get; set; }

public virtual List<Calificaciones> calificaciones { get; set; }

}

and this

public class Calificaciones
{

const double MIN_VALUE = 0.0;
const double MAX_VALUE = 5.0;

public int Id { get; set; }

[Required]
public int materiasId { get; set; }
public virtual Materias materia { get; set; }

[Required]
[Display(Name = "Nota 1")]
[Range(minimum: MIN_VALUE, maximum: MAX_VALUE, ErrorMessage = "Debe ingresar un numero entre 0.0  y 5.0")]
public Double nota1 { get; set; }

[Required]
[Display(Name = "Nota 2")]
[Range(minimum: MIN_VALUE, maximum: MAX_VALUE, ErrorMessage = "Debe ingresar un numero entre 0.0  y 5.0")]
public Double nota2 { get; set; }

[Required]
[Display(Name = "Nota 3")]
[Range(minimum: MIN_VALUE, maximum: MAX_VALUE, ErrorMessage = "Debe ingresar un numero entre 0.0  y 5.0")]
public Double nota3 { get; set; }

[Display(Name = "Resultado")]
public Double resultado { get; set; }


}

the controller is

// GET: Calificaciones/Create
public ActionResult Create()
{
    var materias = db.Materias.ToList();
    ViewBag.materias = materias;
    return View();
}

// POST: Calificaciones/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for 
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "Id,materiasId,nota1,nota2,nota3,resultado")] Calificaciones calificaciones)
{
    if (ModelState.IsValid)
    {
        db.Calificaciones.Add(calificaciones);
        db.SaveChanges();
        return RedirectToAction("Index");
    }

    ViewBag.materiasId = new SelectList(db.Materias, "materiasId", "nombre", calificaciones.materiasId);
    return View(calificaciones);
}

and the view

@model  CalculaNotas.Models.Calificaciones
@{
ViewBag.Title = "Create";
}

<h2>Create</h2>


@using (Html.BeginForm())
{
 @Html.AntiForgeryToken()

<div class="form-horizontal">
 <h4>Calificaciones</h4>

<table class="table table-bordered">
    <tr >
        <th class="col-md-1"> @Html.DisplayNameFor(model => model.materia) </th>
        <th class="col-md-1" style="text-align:center">@Html.DisplayNameFor(model => model.nota1)</th>
        <th class="col-md-1" style="text-align:center">@Html.DisplayNameFor(model => model.nota2)</th>
        <th class="col-md-1" style="text-align:center">@Html.DisplayNameFor(model => model.nota3)</th>
    </tr>

    @foreach (var materia in (IEnumerable<CalculaNotas.Models.Materias>)ViewBag.materias)
    {
        <tr >
            <td class="col-md-1">@Html.DisplayFor(model => materia.nombre)</td>
            <td class="col-md-1">
                @Html.EditorFor(model => model.nota1, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.nota1, "", new { @class = "text-danger" })
            </td>
            <td class="col-md-1">
                @Html.EditorFor(model => model.nota2, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.nota2, "", new { @class = "text-danger" })
            </td>
            <td class="col-md-1">
                @Html.EditorFor(model => model.nota3, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.nota3, "", new { @class = "text-danger" })
            </td>

the view render:

I want to create multiple rows

i tried wit IEnumerable but it doesn't work any help?