I found this code, I want to convert this Razor code to aspx view engine, also please explain to me the purpose from this code.

<script>
$(document).ready(function(){
$("#btn-register").click(function () {
    var posting = $.post("api/Register",
        $("#saveContactForm").serialize(),
        function(value) {
            console.log(value);
        },
        "json"
    ).complete(function (data) {
        alert(data.responseText);
    });
    return false;
});

});

I have my models like this:

  1. Goup.cs
  2. GroupUser (pivot table)
  3. ApplicationUser (User) -> 4. Profile

And now I want to show the data in Profile on a details page when the User belongs to the group. I'm doing this like this:

private IEnumerable<GroupUser> GetUsers(int groupId)
    {
        IEnumerable<GroupUser> model = null;

        if(groupId == 0)
        {
            model = _kletsContext.GroupUser.OrderByDescending(o => o.GroupId).AsEnumerable();
        }
        else
        {
            model = _kletsContext.GroupUser.Where(g => g.GroupId == groupId).Include(p => p.User.Profile).OrderByDescending(o => o.GroupId).AsEnumerable();
        }

        return model;
    }

This works, if I just want to display the UserId, ... (so the data in the Pivot table) with this code:

@model IEnumerable<App.Models.GroupUser>
@if(Model != null && Model.Count() > 0)
{   
@foreach(var user in Model)
{
@user.UserId</h2>
}
}

But for some reason I can't display the data in the Included tables? Normally you would do something like this: @user.User.Profile.XXXX but then I get the error: System.NullReferenceException: Object reference not set to an instance of an object So this would mean the return is null, but there are users in the pivot table with a profile.

The models:

Group.cs:

namespace App.Models
{
public class Group : Item
{
    public Group() : base()
    {

    }

    [Key]
    public Int16 Id { get; set; } 
    public string Name { get; set; }
    public string Images { get; set; }

    /* Foreign Keys */
    public Nullable<Int16> RegionId { get; set; }

    public virtual Region Region { get; set; }
    public virtual ICollection<Lets> Lets { get; set; }
    public virtual ICollection<GroupUser> Users { get; set; }
}
}

ApplicationUser:

namespace App.Models.Identity
{
public class ApplicationUser : IdentityUser
{   
    public string Description { get; set; }
    public DateTime CreatedAt { get; set; }
    public Nullable<DateTime> UpdatedAt { get; set; }
    public Nullable<DateTime> DeletedAt { get; set; } 

    /* Virtual or Navigation Properties */
    public virtual Profile Profile { get; set; }
    public virtual ICollection<GroupUser> Groups { get; set; }    
    public virtual ICollection<Lets> Lets { get; set; }  
    public virtual ICollection<Category> Categories { get; set; } 
    public virtual ICollection<Region> Regions { get; set; }    
    public virtual ICollection<Status> Status { get; set; }   
    public virtual ICollection<Tag> Tags { get; set; }   
}
}

GroupUser:

namespace App.Models
{
public class GroupUser
{
    public GroupUser()
    {

    }

    public Nullable<Int16> GroupId { get; set; }
    public string UserId { get; set; }
    public virtual Group Group { get; set; }
    public virtual ApplicationUser User { get; set; }
}
}

Profile.cs:

namespace App.Models
{
public class Profile : Item
{
    public Profile() : base()
    {

    }

    [Key]
    public string UserId { get; set; } 
    public string FirstName { get; set; }
    public string SurName { get; set; }
    public string Email { get; set; }
    public string Gender { get; set; }
    public Int16 Age { get; set; }
    public string City { get; set; }
    public string Image { get; set; }
    public Int16 Credits { get; set; }
    public Int16 Postalcode { get; set; }
}
}

How can i display the nested data with razor?

Today I quickly developed a new vNext class library, called Sales.Data, to act as the DAL for an MVC 6 UI project. I am somewhat out of my depth with ASP.NET 5, MVC6, DNX, and whatever else "vNext" includes, but eventually, with a lot of trial and error, and a lot of googling, I somehow managed to turn a standard class library into a vNext library, but now I cannot reference it from my xUnit DNX test project, nor from my MVC 6 UI project. The library uses NHibernate for very basic data access, just to establish proof of concept. This is what the bottom part of its `project.json' looks like, and whether it makes sense or not why it looks like this, at one stage my test project could at least reference the library, if not run a test. Now it cannot even reference it. What is wrong with this project's dependencies and frameworks configuration?

"frameworks": {
  "net46": {
    "dependencies": {
      "FluentNHibernate": "2.0.3",
      "log4net": "2.0.5",
      "NHibernate": "4.0.4.4000",
      "Microsoft.Framework.ConfigurationModel": "1.0.0-beta4",
      "Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta4"
    }
  }
},
"dependencies": {
  "System.Diagnostics.Tools": "4.0.0"
}

I have a website, and a database of course using SQL Express. I need a report viewer, to show a report from a database. I have my table, added a view to the database, created a dataset and related it to the view, and I created a report (related it to the dataset). Then I have my report viewer and script manager.

The problem is that when I run the website, the report viewer does not show up. it just shows a blank space.

And for debugging purposes, I added a Gridview and assigned it the same sqldatasource, and it is working fine.

What could possibly be the problem?

I have an ASP.Net web application hosted on server1.

There is a drive mapped on server1 from another machine server2. Both server1 and server2 are on different domain.

When I take RDP of server1 I can access that mapped drive. But problem is ASP.Net application is unable to access it. I want to write some files in it but unable to do so.

How can I assign proper rights to my ASP.Net application so it can write files in that mapped drive?

Please note:

  1. My application is hosted on server1 where drive is mapped
  2. Server2 is the machine from where drive is shared on network

  1. i add the combobox column when iam triyng to insert the record from gird iam facing the proble

    GridViewComboBoxColumn valuecolumn = new GridViewComboBoxColumn(); valuecolumn.HeaderText = "value"; valuecolumn.DataSource = dt2; valuecolumn.ValueMember = "Id"; valuecolumn.DisplayMember = "value";

        valuecolumn.Width = 200;
        this.radGridView2.Columns.Add(valuecolumn);
    

    for (int i = 0; i < radGridView2.Rows.Count; i++) {

                string query = "INSERT INTO Attendensevalue (value,stdadminid,Date)values("
                + radGridView2.Rows[i].Cells["value"].Value + ", "
                + radGridView2.Rows[i].Cells["AdmissionNo"].Value + "," + dtpIssueDate.Value + ");";
                cmd = new SqlCommand(query, con);
    

The HTML template file is not exist in the 'add new item' window to App_Data folder, but it exists if I choose add new item to the root!

if I have the following two models :

public class Book
{
    public int ID { get; set; }
    public string Title { get; set; }
    //other properties
    public virtual Category Category { get; set; }
}


public class Category
{ 
    public int ID { get; set; }
    public string CategoryName { get; set; }
    public virtual ICollection<Book> Books { get; set; }
}

And I'm sending List<Book> to the View :

public class ShopController : Controller
{
    private BookStoreMDFEntities db = new BookStoreMDFEntities();
    public ActionResult Index()
    {
        var list = db.Books.Include("Category").ToList();
        return View(list);
    }
}

How can I view the Category names and occurrence number of each category in this Book list ?
Sample Output:

  • Science : 2
  • Maths:4 ...

When I use Visual Studio 2013 to create a new MVC project, I notice that in the _Layout.cshtml file, there is a default link in the menu bar.

@Html.ActionLink("Application name", "Index", "Home", 
      new { area = "" }, new { @class = "navbar-brand" })

It all makes sense for me except the new { area = ""} part. Intellisense says that this parameter is for route values.

I did a Google search for "Html.Actionlink route value area" (and other permutations), but was unable to find any simple definitions of what an "area" is.

Is there a simple explanation for what an "area" is? I have never used this attribute in any of my ActionLinks before.

I want to test WebMethod of some Web Service (asmx). Suppose I have the following code:

    public IUsersRepository UsersRepository
    {
        get { return Session["repository"] as IUsersRepository; }
        set { Session["repository"] = value; }
    }

    [WebMethod(EnableSession = true)]
    public int AddUser(string userName, int something)
    {
        var usersRepository = Session["repository"] as IUsersRepository;
        return usersRepository.AddUser(userName, something);
    }

and the corresponding unit test (just to test that the repository is called at all):

    [Test]
    public void add_user_adds_user()
    {
        // Arrange
        var repository = new Mock<IUsersRepository>();
        var service = new ProteinTrackingService { UsersRepository = repository.Object };

        // Act
        var userName = "Tester";
        var something = 42;
        service.AddUser(userName: userName, something: something);

        // Assert
        repository.Verify(r => r.AddUser(
            It.Is<string>(n => n.Equals(userName)),
            It.Is<int>(p => p.Equals(something))));
    }

When I run this test, I receive the following erro message: System.InvalidOperationException : HttpContext is not available. This class can only be used in the context of an ASP.NET request. What shall I do to make this test working?

I have created class Auction.cs with this code behind :

namespace WebApplication5
{
    public class Auction
    {
        public string Productname { get; set; }
        public string Lastbidder { get; set; }
        public int Bidvalue { get; set; }

    private List<Auction> listaAukcija = new List<Auction>();

    public List<Auction> ListaAukcija
    {
        get { return listaAukcija; }
        set { listaAukcija = value; }
    }


    public void getAll()
    {
        using (SqlConnection conn = new SqlConnection(@"data source=JOVAN-PC;database=aukcija_jovan_gajic;integrated security=true;"))
        {
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = @"SELECT a.id AS aid, p.name AS pn, u.name AS un, a.lastbid AS alb FROM (Auction a INNER JOIN Product p ON a.productid = p.id) INNER JOIN User u ON a.lastbider = u.id";
            conn.Open();
            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                listaAukcija.Clear();

                while (reader.Read())
                {
                    Auction auction = new Auction();

                    if (reader["aid"] as int? != null)
                    {
                        auction.Productname = reader["pn"] as string;
                        auction.Lastbidder = reader["un"] as string;
                        auction.Bidvalue = (int)reader["alb"];
                    }

                    listaAukcija.Add(auction);
                }
            }
        }
    }

    public override string ToString()
    {
        return base.ToString();
    }
}
}

I called it's methods in another class called DbBroker.cs :

 public class DbBroker : Home
{
    Auction aukcija = new Auction();

    public void executeQuery()
    {
        aukcija.getAll();
    }


    public void getArr()
    {
        List<string[]> lista = aukcija.ListaAukcija.Cast<string[]>().ToList();
        var x = ListBox1.Text;
        x = lista.ToString();
    }
}

And called getArr on Home page :

public partial class Home : System.Web.UI.Page
{
    DbBroker dbb = new DbBroker();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Label3.Text = Session["Username"].ToString();
            dbb.getArr();
        }

    }
}

Problem is, i get StackOverflowException error on Auction aukcija = new Auction(); in DbBroker.cs class. I don't know why or how to solve it.

i have confusion to practice webtechnologies in which pattern,patch

please any one suggest the best way

How to get caller IP addres in ASP.NET MVC4 Global.asax.cs Application_Start event ? HttpContext.Current.Request object is not available there. Thread.CurrentPrincipal.Identity exists.

I want to log user name and IP address which were used to start application.

MVC4 application runs in Windows and in Mono

I am using asp.net 4.0 website. I have created login page and redirect to exmp.aspx page. But after successful login, it goes to exmp.aspx but again redirect to login page only. Code is correct. May be need any configuration?

I am using cp3001.databasemart.com server provider.

Kindly assist me

Thanks in advance.

I have one bootstrap button dropdown where i need when form data should save after that in jquery script i want to show default value in this dropdown i am not loading the page happening in client side only. Below is my code:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>

<div class="btn-group" style="width:160px">
  <button type="button" class="form-control btn btn-default dropdown-toggle" data-toggle="dropdown">
    Select Gender <span class="caret"></span>
  </button>
  <ul class="dropdown-menu dropdown-menu-right" role="menu">
    <li><a tabindex="-1" href="#">Select Gender</a></li>
    <li><a tabindex="-1" href="#">Male</a></li>
    <li><a tabindex="-1" href="#">Female</a></li>
  </ul>
</div>

So in this code i need once form submitted and shows value from success of ajax call there i need to set dropdown value of first list which value is "Select Gender".

Thank you in advance and please excuse if this one has previously been answered.

I wanted to display a record count. I put a counter in item_databound and noticed that the counter was double the records displayed.

I have a data access layer handling datagrids as:

Case "DataGrid"
            If Len(DataValueField) > 0 Then
                Dim oDS As New DataSet
                Dim oDV As New DataView
                oDV = DataTable.DefaultView
                oDV.Sort = DataValueField & " ASC"
                oDS.Tables.Add(oDV.ToTable)
                CType(WebControl, DataGrid).DataSource = oDS
                CType(WebControl, DataGrid).DataBind()
            Else
                CType(WebControl, DataGrid).DataSource = _DataSet
                CType(WebControl, DataGrid).DataBind()
            End If
            CType(WebControl, DataGrid).DataSource = _DataSet
            CType(WebControl, DataGrid).DataBind()

If I use this code on the page itself Item_Databound only runs once:

        Dim oDA As New SqlDataAdapter(SQL, _oConn)
        Dim oDS As New DataSet
        oDA.Fill(oDS)
        grdUsers.DataSource = oDS
        grdUsers.DataBind()

What am I doing wrong in my DAL that is causing the firing twice?

Thanks, Fudd

I run VS2015 as administrator, start a new project ASP.NET application, Empty 4.5.2 and then just add a simple html page. When I try to launch using IIS Express I just get waiting for local host. If I do this under IIS local it works fine.

I've looked at a number of solutions but have been unable to resolve the problem. I'm a newbe to all of this so would appreciate step by step instructions on how to resolve.

it is a .net framework 4.5.2

How can I generate docs in a nice format such as:
https://dev.fitbit.com/docs/body/#log-body-fat
https://jawbone.com/up/developer/endpoints/moves

Is there a service that can help with this task? I'm using asp.net MVC and WebApi

i wrote the Code for my Login Page and it works well, now i Design the Page and there starts my Problem.

<body>
    <form id="form1" runat="server">
    <div id="content">

    <ul class="pageitem">
        <li class="smallfield"><asp:TextBox id="tbloginuser" runat="server" MaxLength="10" placeholder="Username"></asp:TextBox></li>
        <li class="smallfield"><asp:TextBox id="tbloginpass" runat="server" MaxLength="10" TextMode="Password" placeholder="Password"></asp:TextBox></li>
        <li class="button"><asp:Button ID="loginPage" runat="server" Text="Login" /></li>
    </ul>

    </div>
    </form>
</body>

In the Code Behind "tbloginuser.Text" did not find the ID, if i only use

<asp:TextBox id="tbloginuser" runat="server" MaxLength="10" placeholder="Username"></asp:TextBox>
<asp:TextBox id="tbloginpass" runat="server" MaxLength="10" TextMode="Password" placeholder="Password"></asp:TextBox>
<asp:Button ID="loginPage" runat="server" Text="Login" />

i got no Problem. Can you guys help me out? Thx!

I have the following jQuery in a user control using a Telerik RadGrid:

<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.4.js"></script>
    <script type="text/javascript">
       
        var warnMessage = "You have attempted to leave this page.  If you have made any changes to the fields without clicking the Save and Continue button, your changes will be lost.  Are you sure you want to exit this page?";

        $(document).ready(function () {
            $('input:not(:button,:submit),textarea,select').change(function () {
                window.onbeforeunload = function () {
                    if (warnMessage != null) return warnMessage;
                }
            });
            $('input:not(:button,:submit),textarea,select').on('DOMNodeRemoved', function () {
                window.onbeforeunload = function () {
                    if (warnMessage != null) return warnMessage;
                }
            });
            $('input:submit').click(function (e) {
                warnMessage = null;
            });
        });
    </script>

What it's meant to do is to keep a user from clicking away from the page using several of these controls without saving their changes. When I run this in VS2013, it works fine, triggering the pop-up when anything is added/updated/deleted in the RadGrid and the user attempts to leave the page without saving. However after publishing to the test server,the .click is never hit, so when a user tries to add another entry to the grid, the warning message fires again, and the on DOMNodeRemoved never works. Is there something I'm doing wrong in the code? Or is there something wrong with the server? I'm new to jQuery, so any help would be greatly appreciated. I will post more info if needed.

This question already has an answer here:

ERROR: XMLHttpRequest cannot load http://ogunadsay2-001-site1.btempurl.com/LoginService.asmx. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://ogunadsay-001-site1.btempurl.com' is therefore not allowed access.

I've seen tons of solutions and everyone of them are different. I didn't understand what to do with them. So please help me. Can't i solve this by adding a header to my web service's code or web page's code? Here are my codes.

$.ajax({
            url: "http://ogunadsay2-001-site1.btempurl.com/LoginService.asmx",
            type: "POST",
            dataType: "json",
            data: JSON.stringify({ kullaniciAd: kullaniciAd, sifre: sifre }),
            contentType: "application/json; charset=windows-1254",

it goes like that.

and web service code:

public bool Login(string kullaniciAd, string sifre)
    {
        try
        {
            SqlConnection conn = new SqlConnection("someConnectionString");
            if (conn.State == ConnectionState.Closed)
                conn.Open();

            SqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM tblKullanici WHERE kullaniciAdi = @kullaniciAd AND kullaniciSifre = @kullaniciSifre");
            cmd.CommandType = CommandType.Text;
            cmd.Connection = conn;
            cmd.Parameters.AddWithValue("@kullaniciAd", kullaniciAd);
            cmd.Parameters.AddWithValue("@kullaniciSifre", sifre);
            int bulunanKombinasyon = (int)cmd.ExecuteScalar();
            conn.Close();
            if (bulunanKombinasyon < 1)
            {
                //yanlış giriş
                return false;
            }
            else
            {
                return true;
            }
        }
        catch (SoapException se)
        {
            throw se;
        }
    }

NOTE: they are seperated. I've a solution with web services and I've have solution with web pages. They all deployed smarterasp.net in different hosts.