asp.net-mvc-5

MVC5 application with Rotativa does not work when published on IIS

霸气de小男生 提交于 2019-12-12 01:39:31
问题 I am using Rotativa for convert the view to PDF. It works on my local but when published on IIS server it gives error as below: Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [Exception] Rotativa.WkhtmltopdfDriver.Convert(String wkhtmltopdfPath, String switches, String html) +1364 Rotativa.WkhtmltopdfDriver

“No Key Defined” error message, when creating a view for a view model

岁酱吖の 提交于 2019-12-12 01:36:15
问题 Currently I am creating a project following 'MVC Music Store' tutorial, when come to create a view for "ShoppingCartViewModel", it always shows the error that tells me that there is no Key definied . The error message is: Entity type'ShoppingCartViewModel' has no key defined.... Here is the original code from the tutorial: namespace MyMVStore.ViewModels { public class ShoppingCartViewModel { public List<Cart> CartItems { get; set; } public decimal? CartTotal { get; set; } } } Here is what I

Data collection between ages in mvc5

喜夏-厌秋 提交于 2019-12-12 01:27:26
问题 **hi gays I have tried to collect data between ages but there is an error I do not know why here is my code my controller ** public ActionResult AllCuont() { var query = (from t in db.Pations let range = ( t.Age >= 0 && t.Age < 10 ? "0-9" : t.Age >= 11 && t.Age < 15 ? "10-14" : t.Age >= 15 && t.Age < 50 ? "15-50" : "50+" ) group t by range into g select new UserRange { AgeRange = g.Key, Count = g.Count() }).ToList(); //add the sum column. query.Add(new UserRange() { AgeRange = "Sum", Count =

EF6 with new database generates 'The model backing the <Database> context has changed since the database was created.'

折月煮酒 提交于 2019-12-12 00:50:47
问题 I have been developing a Code First database via migrations for a couple of weeks. I added a few tables yesterday and got the error The model backing the 'DanceDb' context has changed since the database was created. After trying a couple of things I dropped the database, removed all code migrations, cleaned the solution, added a single migration and ran an Update-Database but I still get the same error. If I run Add-Migrations again, nothing is generated so something thinks they're the same.

Overloaded ViewModel Constructor and HttpPost in ASP.NET MVC

断了今生、忘了曾经 提交于 2019-12-12 00:02:30
问题 The closest question I found in StackOverflow to what I have is Posting data when my view model has a constructor does not work Model public class Customer { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } } ViewModel public class CustomerViewModel { public Customer Customer { get; set; } public CustomerViewModel(Customer customer) { Customer = customer; } } Controller Code public ActionResult CreateCustomer() { Customer c = new Customer(

Return a collection of models from a view

China☆狼群 提交于 2019-12-11 22:10:18
问题 I have a requirement to dynamically create objects in my Razor View and after the user edits them, submit them back to the server. This is how my model looks like: public class Panel { public string Name { get; set; } public string Text1 { get; set; } public string Text2 { get; set; } } What I want to do is to render the required inputs each time the clicks on a button using Javascript . this is how my main view looks like: @model IEnumerable<TabsTest.Models.Panel> @using (Html.BeginForm()) {

Save a list of objects mvc5

我只是一个虾纸丫 提交于 2019-12-11 21:42:21
问题 I have the following object: public class CarModelList { public List<CarModel> CarsList { get; set; } } The CarModel is as follows: public class CarModel { public long Id { get; set; } public string Color { get; set; } public List<SelectItem> ColorList { get; set; } public string Seats { get; set; } public string Model { get; set; } public string Year { get; set; } } I have a view which on loading first displays 3 checkboxes : Sea, Air, Soil. If one checkbox is checked a tab is shown with the

Passing parameter across controllers

余生颓废 提交于 2019-12-11 20:57:54
问题 My goal is to save a record in different controller that is associated with a item in a current detail view. I have a detail view this displays a list of associated records from a different table using the following code: <table class="table"> <tr> <th> Date </th> <th> Notes </th> <th> Contractor </th> </tr> @foreach (var item in Model.ServiceHistories) { <tr> <td width="200px"> @Html.DisplayFor(modelItem => item.Date) </td> <td> @Html.DisplayFor(modelItem => item.Notes) </td> <td> @Html

Create a Create view for a Menu With a Dropdownlist from another Model for the dishes

限于喜欢 提交于 2019-12-11 20:06:42
问题 i'm a student and needs to make a application for school. This is a reservation application for a restaurant. I want to create a Create view for the menu where you can give the menu a name and you choose which dishes this menu needs to have. These dishes are stored in another model. I'm using this question: Create a Dropdown List for MVC3 using Entity Framework (.edmx Model) & Razor Views && Insert A Database Record to Multiple Tables but not get it to work. This is my model: public class

Using ViewBag in Layout page

℡╲_俬逩灬. 提交于 2019-12-11 19:53:24
问题 I have my _Layout.cshtml file that uses the ViewBag model to render some dynamic content. I understand ViewBag can be populated in the controller and accessed in the view and/or layout page. My question is, if my Layout page is using @ViewBag.SiteName , I want to avoid having to set this variable in each controller before I return the view. Is there a way to set this variable on a global level? Or how else should I pass this data to the layout page? 回答1: If you set anything in ViewBag - this