I have MVC Project that contain many views, I want the client to edit the content as he/she like and save it.

How I can make CMS (content management system )of the views?

I have read about RedEditor in telerik but it work only with html files , the MVC is cshtml files that contain razor?

I have a controller which returns a list of object, i need to display it to a partialview. So what I want is that the partial view inside the non partial view will accept the result and not the non partial view.

This is the "NON" partial view named "Index"

My table headers are here:

<tbody>
     @Html.RenderPartial()
     Action("DashboardSearchResult","Dashboard",new { List<ReservationType                       >reservationList})
</tbody>

This is my partial view named "_Dashboard"

@model IEnumerable<HotelOrganization.Models.ReservationType>
@foreach (var item in Model)
{
<tr>
<td>@Html.DisplayFor(modelItem => item.ReservationId)</td>
<td>@Html.DisplayFor(modelItem => item.ReservationStartDate)</td>
<tr>

This is my controller:

public PartialViewResult DashboardSearchResult(List<ReservationType>reservationList)
{
return PartialView("~/Views/Shared/_Dashboard", reservationList);
}

I have ViewModel for example

class CustomerViewModel {
// ...
public string Name {get; set;}
public CategoryViewModel CategoryVM {get; set;}
}

class CategoryViewModel {
// ... 
public string Name {get;set;}
}

In View i can get Id of an html element with html helper

<!-- Customer Name -->
@Html.IdFor(m => m.Name)

<!-- Category Name -->
@Html.IdFor(m => m.CategoryVM.Name)

But what if CategoryVM is inserted into PartialView

@{Html.RenderPartial("~/.../_Category.cshtml", Model.CategoryVM);}

How to get Id of the property ? Because now i have two id's with same name. What is best practice for properties naming and handling in nested ViewModels ?

Also i dont want to pass whole Model to the PartialView because there are Ajax calls, which re-renders the partial view, and i dont want to build whole Model from scratch even for simple operations.

I have this strange situation where I have a WebMethod in WebService which needs to return a generic list v and also need to have output Parameter attached to it.And $.ajax({ }) need to call this webservice and get both return value and outparameter in .success().. Web Service is as below:

[WebMethod]

public static List<Category>(out int TotalCountRecord) { List<Category> AllValues= new List<Category>(); //Some ADO.NET Code to Call Stored Procedure with output Value; SqlParameter OutParameter = new SqlParameter("@RecordCount", SqlDbType.Int); OutParameter.Direction = ParameterDirection.Output; cmd.ExecuteNonQuery(); TotalCountRecord= (int)(OutParameter.Value); //Pls. Don't Mind these sequence of the code. return AllValues; }

Now is there a Possible way for me to call these code for JQuery Ajax.Like var a=0; $.ajax({ url: 'WebService1.asmx/LoadGrid', method: 'post', dataType: 'json', data: JSON.stringify({TotalCountRecord:a}), contentType: 'application/json; charset=utf-8', success: function (data) { //Add data to Table //Show RecordCount at Footer of the Table }

.. Is these a way to address this suitation..!! Thanks in advance

Exception - Cannot convert lambda expression to type 'System.Reflection.PropertyInfo' because it is not a delegate type

@model IEnumerable<object>
@using GridMvc.Html;
@using System.Linq;
<link href="~/Content/Gridmvc.css" rel="stylesheet" />
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/gridmvc.min.js"></script>


@{
    ViewBag.Title = "User Grouping";
}
@{
    var grid = new System.Web.Helpers.WebGrid(source: Model, canPage: true, rowsPerPage: 50);
}
@grid.GetHtml()

@Html.Grid(Model).Columns(columns =>
{
    columns.Add(u => u.User).Titled("User Name").SetWidth(110);
    columns.Add(a => a.Amount).Sortable(true);
}).WithPaging(20)

now if you have only one context for database , like applicationDbContext you are only have to run code in package nug >

PM>Enable-Migrations -ContextTypeName ApplicationDbContext -EnableAutomaticMigrations

I have one onthor dbcontext named MyDbContext in models, this for my own created models connection and ApplicationDbContext is only for user maintenance, because I have applied role not delete on MyDbContext for models relation which if I apply not delete in ApplicationDbContext it will distry the user and role identities so I applied in separate DbContext

in DbContext for not delete on relation is :

protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();

        }

now how I am able to enable auto migration in both context in same project or just not delete for some moduls in applicationDbContext

thanks in advance

I have an ASP Core Project and I want to read from a relative solution file that is located in the wwwroot folder:

        //Open html email
        var html = System.IO.File.ReadAllText("mail/activated.html");

Locally things work fine, publishing to Azure causes the following exception:

System.IO.DirectoryNotFoundException: Could not find a part of the path 'D:\home\site\wwwroot\mail\activated.html'.

I've tried using IHostingEnvironment and ~/ which all give me the right path to the file and I see my files in Cloud Explorer so I know they are uploaded correctly to the server. When I try to open the file in the browser, things also work fine.

What am I missing here?

When i use 'Password Recovery' Control to recover any password, Then the email receive encrypted password and also the value of password in SQL provider membership changed from clear to encrypted password? So is there any way to recover clear password?

Please have a look on attached snapshots. before after

Thanks

So I have this web application developed in ASP.NET and using NHibernate for the data access layer, now the whole project was developed to work with Sql Server and works fine, but now I've been tasked to make it compatible with MySql. In the web.config file, I've changed some properties in the nhibernate configuration section.

This where the original values:

<session-factory xmlns="urn:nhibernate-configuration-2.2">
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
        <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
        <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
        <property name="connection.connection_string_name">{my connection string}</property>
        <property name="cache.use_query_cache">true</property>
        <property name="cache.use_second_level_cache">true</property>
        <property name="show_sql">false</property>
        <property name="format_sql">false</property>
        <property name="adonet.batch_size">20</property>
        <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
        <property name="hbm2ddl.keywords">auto-quote</property>
        <property name="generate_statistics">true</property>
        <property name="cache.provider_class">NHibernate.Caches.SysCache2.SysCacheProvider, NHibernate.Caches.SysCache2</property>
        <property name="cache.use_query_cache">true</property>
        <property name="cache.use_second_level_cache">true</property>
    </session-factory>
</hibernate-configuration>

This is how it is now:

<hibernate-configuration>
    <session-factory xmlns="urn:nhibernate-configuration-2.2">
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
        <property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
        <property name="dialect">NHibernate.Dialect.MySQL5Dialect</property>
        <property name="connection.connection_string_name">{my connection string}</property>
        <property name="cache.use_query_cache">true</property>
        <property name="cache.use_second_level_cache">true</property>
        <property name="show_sql">false</property>
        <property name="format_sql">false</property>
        <property name="adonet.batch_size">20</property>
        <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
        <property name="hbm2ddl.keywords">auto-quote</property>
        <property name="generate_statistics">true</property>
        <property name="cache.provider_class">NHibernate.Caches.SysCache2.SysCacheProvider, NHibernate.Caches.SysCache2</property>
        <property name="cache.use_query_cache">true</property>
        <property name="cache.use_second_level_cache">true</property>
    </session-factory>
</hibernate-configuration>

Note that I've only changed the "connection.provider", "connection.driver_class" and "dialect" properties. At first everything works fine, I can connect to the MySql server, generate the database automatically, run queries and insert rows, the problem I'm having is that whenever I have a dirty entity object and try to update it, I get a StaleObjectStateException with the message Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [MyEntityType#32613962-6533-6631-2d37-6334342d3461].

This is the code I'm using to update:

  ITransaction transaction = this.Session.BeginTransaction();
  try
  {
    this.Session.Merge<T>(entity);
    this.Session.Flush();
    transaction.Commit();
  }
  catch (Exception ex)
  {
    transaction.Rollback();
    throw;
  }

This exception is not thrown when using a Sql Server server, and since I'm not familiar with NHibernate, I wanted to ask you guys if there's something I'm missing, Is there something else I have to set up to run the application with a MySql database?

Iam real confused. I want to implement a DropdownList in MVC.

I have seen some examples on internet on this topic.

Its confusing.. in som examples they use SelectList and in some SelectListItems. And in other exsamples they use both selectList and SelectListItem to populate dropdownlist..

Plz help. When to use SelectList and when to use SelectListItem .. ?

I have a Class A and a class B like

class A {
private B b;
private atribute1;
private atribute2;
}

class B {
private string name;

}

I have a datagrid view like this

<asp:GridView ID="grid" runat="server" AutoGenerateColumns="False" >
        <Columns>                      
            <asp:BoundField DataField="Atribute1" HeaderText="Atribute1" />
             <asp:BoundField DataField="Atribute1" HeaderText="Atribute2" />
            <asp:BoundField DataField="b.name" HeaderText="B.NAME" />
        </Columns>
    </asp:GridView

>

What I want to dois to populate the last column with the b.name value, but I can't with this code.

I tried Binding sub Objects to DataField and DataSource but It does not work (Or I am not understanding the workaround proposed there )

In Webconfig file, I want to replace connectionstring with its encrypted form.Using Configurationmanager class I am reading connection string and encrypting it with DPAPI class's Protect() function but finding difficulties when trying to put this encrypted connection string back in webconfig file.

I am trying to run javascript based on TempData that i pass from the controller.

But using the code below with razor, it neve reach to second if statement. I have a feeling that i am not using the proper razor syntax.

@if (TempData["status"] != null)
{
    <script type="text/javascript">
        var status = "@TempData["status"]";
        if (status == "customerAdded") {
            swal("1!", "good", "success")               
        }
        else {            
        }

    </script>
}

I'm trying to make a cinema ticket reservation page in asp.net mvc. I have a matrix of checkboxes i generate in the view that represent the seats, i bind it to an array of bools in the viewmodel.

@Html.CheckBoxFor(x => 
  x.NewReservationTable[i * Model.SeatStatusTable.GetLength(1) + j])

When the user posts the reservation, I get the name and phone number in the controller, I get a null for the array.

Here is my ViewModel:

public class Reservation
{
    public StatusEnum[,] SeatStatusTable { get; set; }
    public List<bool> NewReservationTable { get; set; }
    public Screening Screening { get; set; }
    public Movie Movie { get; set; }
    [Required]
    public string ReserverName { get; set; }
    [Required]
    [DataType(DataType.PhoneNumber)]
    [RegularExpression(@"[+]?\d{2}[(]?\d{2}[)]?\d{3}[-]?\d{4}")]
    public string ReserverPhoneNumber { get; set; }
    public int MaxRow { get; set; }
    public int MaxCol { get; set; }
}

And here is what i post for the viewmodel:

return View(new Reservation()
        {
            Screening = selectedScreening,
            Movie = movie,
            SeatStatusTable = seatsTable,
            NewReservationTable = new List<bool>(new bool[room.RowCount * room.ColumnCount]),
            MaxRow = room.RowCount,
            MaxCol = room.ColumnCount
        });

EDIT: Changed array to list, I initialize it with false values, pass it to the view, and get back a null after the post. I'm a total beginner, any help or suggestion appreciated.

I made a c#.NET WebAPI and it worked when I changed the model it stopped working and it gives me the following error message.

The model backing the 'ApiDbContext' context has changed since the database was created. Consider using Code First Migrations to update the database.

The Model(unchanged):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Test.Models
{
    public class User
    {
        public int Id { get; set; }
        public string Name { get; set; }
        //public DateTime startTime { get; set; }
        //public DateTime endTime { get; set; }
        //public int Age { get; set; }
        //public string Adress { get; set; }
    }
}

The Model(changed):

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;

    namespace Test.Models
    {
        public class User
        {
            public int Id { get; set; }
            public string Name { get; set; }
            public DateTime startTime { get; set; }
            //public DateTime endTime { get; set; }
            //public int Age { get; set; }
            //public string Adress { get; set; }
        }
    }
The Controller(changed at updateUser):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Test.DBA;
using Test.Models;

namespace Test.Controllers
{
    public class UserAPIController : ApiController
    {
        ApiDbContext dbContext = null;
        public UserAPIController()
        {
            dbContext = new ApiDbContext();
        }
        [HttpPost]
        public IHttpActionResult InsertUser(User user)
        {
            dbContext.Users.Add(user);
            dbContext.SaveChangesAsync();

            return Ok(user.Name);
        }

        public IEnumerable<User> GetAllUser()
        {
            var list = dbContext.Users.ToList();
            return list;
        }

        [HttpPost]
        public IHttpActionResult DeleteUser(User user)
        {
            dbContext.Users.Remove(user);
            dbContext.SaveChanges();

            return Ok(user.Name);
        }

        [HttpGet]
        public IHttpActionResult ViewUser(int id)
        {
            var student = dbContext.Users.Find(id);
            return Ok(student);
        }

        [HttpPost]
        public IHttpActionResult UpdateUser(User user)
        {
            User std = dbContext.Users.Find(user.Id);

            std.Name = user.Name;
            std.startTime = user.startTime;
            //std.endTime = user.endTime;
            //std.Age = user.Age;
            //std.Adress = user.Adress;

            dbContext.Entry(std).State = System.Data.Entity.EntityState.Modified;
            dbContext.SaveChangesAsync();

            return Ok();
        }
    }
}

DBContext:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using Test.Models;

namespace Test.DBA
{
    public class ApiDbContext :DbContext
    {
        public ApiDbContext() : base("Connection")
        {

        }
        public DbSet<User> Users { get; set; }
    }
}

Connection string:

<connectionStrings>
   <add name ="Connection" connectionString="Data Source=.\SQLExpress;Initial Catalog=k;Integrated Security=True" providerName="System.Data.SqlClient"/>
  </connectionStrings>

I have created a newsletter application in .Net for one of my clients. The database is hosted on a server and application is also hosted on another server. My question is, when my client will login and create a newsletter (an html file is created). And then send newsletter email to about 50,000 email addresses, what memory resources will be used?

  • Local machine
  • Database server
  • Web Server

P.S. My application loads all email addresses in a server variable and then loop through each value and send's email.

I have a table in my database with file title and its path in the server.

whats the easiest way to list every file title and a button to download it beside the title ?

like a grid view but instead of the actual path a download button for that file?

I have the following Javascript function to Copy Selected(using CheckBox) row values from Gridview1 to GridView2.

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
        var temprow = $('[id*=GridView2] table tbody').find(".emptyTd");

        $('[id*=cbCheck]').change(function () {
            var checkbox = $(this);
            if ($(this).is(":checked")) {
                var row = $(this).parent().closest('tr');
                var temp = $(row).clone(true);
                $('[id*=GridView1] tbody').append(temp);
                $('[id*=GridView2] table tbody').find(".emptyTd").remove();
                $(row).find("td:first").remove();
                $('[id*=GridView2] table tbody').append(row);
            }
            else {
                $('[id*=GridView2] table tbody tr').each(function () {
                    if ($(this).find("td:first").html() == $(checkbox).parent().closest('tr').find("td:nth-child(2)").html()) {
                        $(this).remove();
                        if ($('[id*=GridView2] table tbody').has('td').length == 0) {
                            $('[id*=GridView2] table tbody').append(temprow);
                        }
                    }
                });
            }
        });
    });       
</script>

Now i want to add SELECT and DELETE buttons on GridView2 using Javascript/JQuerry my GidView2 is look like,

<asp:GridView ID="GridView2" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
    runat="server" AutoGenerateColumns="false" OnSelectedIndexChanged="GridView2_SelectedIndexChanged">
 <EmptyDataTemplate>
        <table border="0" cellpadding="0" cellspacing="0" width="325px">
            <tr style="color: White; background-color: #3AC0F2;">

                <th scope="col">
                    Item Code
                </th>
                <th scope="col">
                    Item Name
                </th>
                <th scope="col">
                    Unit
                </th>
                <th scope="col">
                    Price
                </th>
                <th scope="col">
                    Stock
                </th>
            </tr>
            <tr class="emptyTd">
                <td style="width: 30px; text-align: center" colspan="3">
                    No Records found
                </td>
            </tr>
        </table>
    </EmptyDataTemplate>
</asp:GridView>

I'm currently refactoring multiple applications which access the same database for users. Each adds their own special properties to the user which results in a lot of null values... i do not like this. My idea was to use a own IdentityUser, dbContext and UserManager per Application. There is a base IdentityUser and the other ones derive from it. it looks like this:

The base user:

 public class User : IdentityUser
 {
   public string Username {get;set;}
   public string Email {get;set;}
   ...
 }

The dbContext and userManager for this user:

public class UserAuthenticationDbContext : IdentityDbContext<User>
{
  //code here
}

public class UserManager : UserManager<User>
{
 //code here
}

For the second user i did the following:

[Table("User2")]
public class User2 : User
{
    public string SpecialProperty1 {get;set;}
    public string SpecialProperty2 {get;set;}
}

public class User2Manager : UserManager<User2>
{
  // code here
}

public class User2AuthenticationDbContext : IdentityDbContext<User2>
{
   //code here
}

The User2 table only has the two Properties for example. The Primary Key in User2 is the same as in the User Table and also a FK to it.

In an asp.net mvc Project i use only for example the User2 related classes. If i now start this application i get instantly the error message "Invalid Column name SpecialProperty1 and SpecialProperty2". Entity Frameworks seems to access the User Table which does not have this additional fields. It does not "merge" it with the User2 Table and return a User2 Entity. What can i do to achieve this or is there a different/better way on how to do it?

My main goal is to make this more clean and separate for this multiple applications while still all applications access the same database.

In Visual Studio 2015 Community Edition, I run my .NET Core Web API application via console by choosing [AppName] from running profile options on toolbar (Near Little green triangle, dropdown menu). The default options are IIS Express and [AppName], which runs dotnet restore and dotnet run from command prompt.

After I reinstall Windows 10 and therefore VS2015, I can no longer see default [AppName] option in the dropdown and I am trying to enable it again. It has just one option, which is IISExpress.

The dropdown menu for running options

I've also installed dot net core tools for VS2015. How can I enable it again?

Thanks.

I have been searching for positioning different panels at User Interface by user(simply dragging with mouse).How can i start with it?Please help me with this topic.Any small help too appreciated!!!

Thanks in advance