spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » ASP NET MVC » Page 1
{System.InvalidOperationException: The parameter conversion from type 'System.String' to type 'System.Collections.Generic.KeyValuePair
An IEnumerable<SelectListItem> is required for a dropdown list, but that is an interface and not a solid implementation... e.g. "what sort of IEnumerable should I create when I serialise? I have no idea!" Change that member to a List<SelectListItem> [Required] [Display(Name = "Gender")] public string selectedGender { get; set; } public List<SelectListItem> Gend

Categories : Asp Net Mvc

Issuing an token for user without user interaction
Client Credentials Flow defined in RFC 6749 (OAuth 2.0) issues an access token which is not associated with any user, meaning that user login is not needed. It is okay to allow client applications having access tokens issued through Client Credentials Flow to access public information about a user. However, if you allowed them to access private information about a user (= information that should

Categories : Asp Net Mvc

Kendo Datepicker disables "today" if using min declaration
This has a very simple solution. Change "DateTime.Now" to "DateTime.Today" and everything will work as you expect. i.e. @(Html.Kendo().DatePicker() .Name("DatePicker") .Value(DateTime.Now) .Format("dd.MMMM yyyy") .Max(DateTime.Now.AddMonths(6)) .Min(DateTime.Today) ) Hope this helps.:)

Categories : Asp Net Mvc

MVC: how can I sign up controller on View events (c#)?
You can't - MVC is stateless (unless you use WebSockets) and it's impossible to keep relations between objects in runtime, when every request is like running new instance of a whole application.

Categories : Asp Net Mvc

How do I reorder my dropdown list in MVC 5?
Just sort them before converting to drop-down list. var values = db.Rating.OrderByDescending(o => o.Rate).ToList(); var dropdownlist = values.Select(s => new SelectListItem{Value = s.Rate.ToString(), Name = s.Name}).ToList(); ViewBag.List = dropdownlist; //in your view Html.DropwDownList("Rating", (List<SelectListItem>)ViewBag.List); If your rating is stored as a string, then yo

Categories : Asp Net Mvc

Not able to retrieve RouteData in a MVC project
The problem is trivial cuz your are not using the mocked HttpContextBase. Replace the second code block with the following. var context = MockHttpContext(); var routeData = RouteTable.Routes.GetRouteData(context); var code = routeData.Values[Constants.CULTURE];

Categories : Asp Net Mvc

Is it must to use entity framework for db handling in MVC?
No it is not a must. You can implement your database layer. But the thing you need is define Models for MVC: public class MyClass { [Display(Name = "SomeName")] [Required(ErrorMessage = "required")] public int? SomeId { get; set; } //... } for scaffolding. Here is example implementation for Ado.net DataAdapter: public class MyController : Controller { public ActionResult

Categories : Asp Net Mvc

Following an action link with a character
Add @: before | inside the if block to tell Razor that | is a content block instead of a C# syntax @if (item.UserCanEdit()) { @Html.ActionLink("Edit", "Edit", new { id = item.Id }) @:| }

Categories : Asp Net Mvc

Passing TempData between controllers
Yes it is possible since TempData is backed by SessionState. It's essentially a special case of session state with a shorter lifespan. Here is a similar question/answer Passing data between different controller action methods

Categories : Asp Net Mvc

NLog use in MVC applicaiton
Since you've already captured the error and you can't show the requested page, you could redirect within the catch to your error page: catch (Exception e) { logger.Error("Error in Index: " + e); return RedirectToAction("Index", "Error"); // Redirect to error controller or page } Alternatively, and probably more appropriate, you could have your action raise a 500 erro

Categories : Asp Net Mvc

How to not disclose Entityframework property names in GET request?
You can do that using a ViewModel, which maps to an entity: public class SearchEntity { public bool SomeBoolProperty { get; set; } public string SearchTerm { get; set; } } public class SearchViewModel { public bool opt1 { get; set; } public string q { get; set; } public SearchEntity ToEntity() { return new SearchEntity { SomeBoolProperty = o

Categories : Asp Net Mvc

asp.net mvc 5 entity framework 6 identity working with trust level = medium?
The component "Identity" from Microsoft needs server with "Full Trust" Level to run. Check Answer from Levi. Visual Studio 2013 Web Forms Site doesn't work with trust level "Medium"

Categories : Asp Net Mvc

Get link to the file returned by a FileContentResult
If you want to axtend the link you can just extend your controller method signature, like this: public ActionResult GetImage(long id , string src, string filter) ASP.NET MVC will bind this values and on your View you can write like this: <img src="@Url.Action("GetImage", new { id=a.Id, src = "myimage.jpg", filter = "greyscale" })"/>

Categories : Asp Net Mvc

How can I get my mvc partial view layout to display in two columns instead of one using kendo mvc
Are u using bootstrap? then the unswer is to use div wrapper with special class 'col-md-6'. Refer to getbootstrap.com for more information. <div class="col-md-6"> <div class="form-group"> <div id="databaselabel">@Html.LabelFor(m => m.database_name, "Database")</div> <div id="databaseedit">@Html.DisplayFor(m => m.database_name, new { @class = "form-con

Categories : Asp Net Mvc

how to remove the collection from modelstate MVC
Add two viewmodels one for update action and one for create action and exclude createdon and updatedon properties from the viewmodels, This way you keep your controllers clean from additional complexity of clearing or adding errors and just test for ModelState.IsValid. If valid then update or create the Student with updatedon or createdon respectivily.

Categories : Asp Net Mvc

EntityType 'SelectListItem' has no key defined. Define the key for this EntityType
You should not be attempting to store SelectListItem in the database, as this is MVC specific concept. Instead create a custom entity class and use it instead; public class Course { public int CourseId { get; set; } public string CourseTitle { get; set; } } public class Student { public int StudentId { get; set; } public string StudentName { get; set; } public ICollection<

Categories : Asp Net Mvc

HTML Attributes not rendering in DropDownList
Try the following code: @Html.DropDownList("Title", ViewData["Actors"] as SelectList, "---Select Actor---", new { @class = "form-control" }) You don't need to explicetely name property htmlAttributes If you want to use the variable name then use this: @Html.DropDownList("Title", ViewData["Actors"] as SelectList, "---Select Actor---", htmlAttributes: new { @class = "form-control" })

Categories : Asp Net Mvc

Why is ViewBag not displaying query result correctly?
projName is currently just an IQueryable object as you have it now. You need to actually EXECUTE the query against the db and save the result in the ViewBag.projectName property. Switching out your var projName = from p in db.Projects where p.ID == id select p.ProjectName; line to the following should resolve this: var projName = db.Projects.Find(id).ProjectName; (this assumes that ID is

Categories : Asp Net Mvc

How to display a List of objects in C# to javascript using Google JS API in MVC3?
It seems like you are browsing to the JSON controller endpoint localhost/MyApp/Chart/Sales (which is consumed by the Ajax callback in google.setOnLoadCallback to feed data to the chart) - it looks like the JsonRresult is working fine. In order to view the Graph, you'll need to browse to the "Sale ActionResult" route (something like localhost/MyApp/SomeController/Sale) You also have a typo: f

Categories : Asp Net Mvc

devexpress scheduler - get resourceId when select cell on same row
In cshtml file: scheduler.ClientSideEvents.SelectionChanged = "OnDispatcherSchedulerItemChanged"; In JavaScript code: function OnDispatcherSchedulerItemChanged(s, e) { alert(s.selection.resource); }

Categories : Asp Net Mvc

Web api 2 - Register, redirect and handling errors
success: function(data) { //here you can handle response from server. If registration fails you should return //validation errors, if not you can return session_token and redirect to some other page (for example) }, error: function (message) { //to handle this - you should throw httpexception in your controller method with 500 error code //and with some short error description. }

Categories : Asp Net Mvc

MVC Bootstrap 3.0 - String data from database not breaking lines in any container
By default new lines in your text are not respected by Html processor. You can Use CSS(This will work for IE 8+) - white-space: pre-line: <p style="white-space: pre-line">@Model.VeryLongString</p> Use C# to replace new line with <br /> if you have to support ancient browsers: @Html.Raw(Html.Encode(Model.VeryLongString).Replace(" ", "<br />"))

Categories : Asp Net Mvc

Rendering action from base controller, getting route not defined error
The first parameter of the RenderAction method is the action name, not the route name. If you're rendering a View that is being generated using a Controller other than the one that defines the SectionNavigation Action, you'll have to specify the Controller name as well: @Html.RenderAction("SecondNavigation", "YourControllerName"). If you're using Areas, you'll have to include the Area name as

Categories : Asp Net Mvc

MVC: AngularJS posted data is null in the cotroller
Basically what you are expecting is for angular js $http.post to behave like jQuery.ajax(). This isn't the case because jquery.ajax transmits with contentType=x-www-form-urlencoded while angular always transmits with contentType=application/json. I would look at your API and check if you can transmit a request with content type json. There are add-on's to browsers that you can use to facilitate th

Categories : Asp Net Mvc

create breadcrumb with MvcSiteMap in mvc5
As stated in the documentation, you must configure all custom route parameters (including id) explicitly. You can create a 1 to 1 relationship with the action method by including the key in PreservedRouteParameters or you can create a 1 to many relationship with the action by creating a separate node for every route value combination. 1 to 1 Relationship Using XML: <mvcSiteMapNode title="New

Categories : Asp Net Mvc

syncfusion error render chart convert void to object
This happens because of specifying the “.Render()” This structure was followed in Syncfusion Essential studio version 12.1.0.36. But it was changed in the future release. Please find the below code snippet for initializing a chart control. [CSHTML] @(Html.EJ().Chart("container")) This standard is followed from Syncfusion Essential studio version 12.2.0.36 to current versions. Thanks,

Categories : Asp Net Mvc

How can i set the html id attribute in razor
Just add the id property to the html-attributes. That will override the default id generated by the editorfor-helper-methode. Look at this post: How can I set id using Html.EditorFor with MVC3 @Html.EditorFor(model => model.News_Date, new { htmlAttributes = new { @class = "form-control", id = "my_custom_id" }})

Categories : Asp Net Mvc

ImageResizing Not Working In Hosting
The self-diagnostics page at /resizer.debug explains the configuration issues present on your hosting environment Image resizer diagnostic sheet 24.11.2014 22:15:04 2 Issues detected: (Critical): Grant the website SecurityPermission to call UrlAuthorizationModule.CheckUrlAccessForPrincipal Without this permission, it may be possible for users to bypass UrlAuthorization rules you

Categories : Asp Net Mvc

Razor DropDownListFor sets selected value when I have no value set
Since your code for view shares Model.SelectOptions object by three dropdowns, the Selected property on each SelectListItem object in the list may be interfered. In your example, when first dropdown is constructed, one of SelectListItem object of which value matches Model.FirstId value will be set to true. On second dropdown creation, as Model.SecondId is null which does not exist in Model.Select

Categories : Asp Net Mvc

MVC M:M capturing each lists objects
Your impression is correct. They are 2 different objects which you can test using bool areEqual = movies[0] == actors[0].Movies[0]; which will return false (unless you have overloaded the == and != operators to compare the Title property for equality). If you wanted them to be the same object then you would need something like var movies = ..... var actors = new List<Actor>() { new Act

Categories : Asp Net Mvc

How to return StatusCode 401 using ASP.Net MVC5 and OWIN
The solution was actually provided in the link which I added to my question. Here is the solution which works great for me: public class StartupAuth { private static bool IsAjaxRequest(IOwinRequest request) { IReadableStringCollection query = request.Query; if ((query != null) && (query["X-Requested-With"] == "XMLHttpRequest")) { return true;

Categories : Asp Net Mvc

How to Use a View Model with LINQ to Entities
You should not have a viewmodel in your dbcontext. This is a viewModel only and is totally different than your entities. public System.Data.Entity.DbSet<FRESH.ViewModel.ManageTasksViewModel> ManageTasksViewModels { get; set; }

Categories : Asp Net Mvc

Adding features while creating User in mvc using checkbox
try with this, in you Model of Feature add a new property public bool isFeatureOf { get; set; } also in your model for the method AddNewUser change it to public void AddNewUser(User userAdd,List<Feature> features) { userService = new UserService(userDbContext); User = userService.AddUser(userAdd); userService.SaveUser(); //featureService = new Fea

Categories : Asp Net Mvc

Asp.Net Mvc Razor Model with @ and with @
There's no difference between using Model and @Model in your @if(...) statement. @ starts a code section or outputs a variable in Razor syntax, and once in code (so in your @if(...)), it is a character to escape reserved words as defined in the C# syntax. For the former see What does the “@” in ASP MVC mean/do?, the latter is explained in What's the use/meaning of the @ character in variabl

Categories : Asp Net Mvc

How To Validate a Devexpress Textbox inside an Devexpress Gridview in Javasacript
When do you need to validate the TextBox? In browser mode or when editing? Currently your TextBox is required when you edit a row. Try to set the IsRequired property for your TextBox in the template as well. txtSettings.Properties.ValidationSettings.RequiredField.IsRequired = true; It should work.

Categories : Asp Net Mvc

Unity PerRequestLifetimeManager re-using object in different requests
The problem turned out to be that the UnityDependencyResolver was caching the resolved items over several requests. I had to change it to the UnityHierarchicalDependencyResolver and then it started resolving my items properly according to the associated LifetimeManager. The problem initially became more confusing when it appeared that even when using a TransientLifetimeManager, it would still retu

Categories : Asp Net Mvc

Partial view - Model binding in ASP.NET MVC 4
The easiest way would be to create an EditorTemplate: @model OrderDetail @Html.HiddenFor(m => m.Id)//your model doesn't seem to have an id? @Html.DisplayFor(m => m.ProductName) @Html.EditorFor(m => m.ProductName) Then in your view with the CustomerOrder model just do this: @Html.LabelFor(model => model.OrderList) @Html.EditorFor(model => model.OrderList)

Categories : Asp Net Mvc

Need to Deploy MVC App to production
We use for the exact same scenario Entity Framework Migrations. It works without any problems. You can easily change the database from version to version. Also downgrading is supported. With some third party tools you can also add other dbms then SQL Server. See http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/migrations-and-deployment-with-the-entity-framework-i

Categories : Asp Net Mvc

NHibernate mapping. Class name the same as property name
The mapping is correct. A fact that some property and some other class name share same name, is not any issue for NHibernate. Check the underlying column content. Run profiler to see the SQL Query and assure that returned data are there... original assumpiton that many-to-one is required removed

Categories : Asp Net Mvc


Recently Add
@model,ViewBag does not exist in the current context
{System.InvalidOperationException: The parameter conversion from type 'System.String' to type 'System.Collections.Generic.KeyValuePair
Issuing an token for user without user interaction
Kendo Datepicker disables "today" if using min declaration
MVC: how can I sign up controller on View events (c#)?
How do I reorder my dropdown list in MVC 5?
Not able to retrieve RouteData in a MVC project
Is it must to use entity framework for db handling in MVC?
Following an action link with a character
Passing TempData between controllers
NLog use in MVC applicaiton
How to not disclose Entityframework property names in GET request?
asp.net mvc 5 entity framework 6 identity working with trust level = medium?
Get link to the file returned by a FileContentResult
How can I get my mvc partial view layout to display in two columns instead of one using kendo mvc
how to remove the collection from modelstate MVC
EntityType 'SelectListItem' has no key defined. Define the key for this EntityType
HTML Attributes not rendering in DropDownList
Why is ViewBag not displaying query result correctly?
How to display a List of objects in C# to javascript using Google JS API in MVC3?
devexpress scheduler - get resourceId when select cell on same row
Web api 2 - Register, redirect and handling errors
MVC Bootstrap 3.0 - String data from database not breaking lines in any container
Rendering action from base controller, getting route not defined error
MVC: AngularJS posted data is null in the cotroller
create breadcrumb with MvcSiteMap in mvc5
syncfusion error render chart convert void to object
How can i set the html id attribute in razor
ImageResizing Not Working In Hosting
Razor DropDownListFor sets selected value when I have no value set
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.