w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
  Home » ASP NET MVC » Page 1
Rendering Multiple (PartialView) Forms On One View Using @foreach
I ended up getting this working using a ViewModel that looks something like this: public class MainViewModel { public List<Form1> Form1{ get; set; } public List<Form2> Form2 { get; set; } public List<Form3> Form3{ get; set; } // etc. public MainViewModel() { Form1 = new List<Form1>(); Form2 = new List<Form2>(); Form3 = ne

Categories : Asp Net Mvc

Make a condition to display a partial view MVC 4
an idea: you could put your partial view within a div and give it an Id. also, give your select control an Id. Then create a javascript function which triggered by the onselect event of the select element. in that js function check the selected value if it's Nueva? then make the partial view div visible if not hide the div set the partial view div by default hidden. please check this similar e

Categories : Asp Net Mvc

Unified MVC and Web Api - same controller for views and json?
This can be done without the new unified model. In any MVC controller you can inspect the headers as well as the Request.IsAjaxRequest() method to determine whether how to return data. Here is bare-bones simplified example of such a method: internal ActionResult ReturnResultAsRequested(object result) { if (Request.Headers["Accept"].Contains("application/json")) return Json(result); else

Categories : Asp Net Mvc

ActionLink not working as expected in MVC 4
In the first case your parameters to ActionLink are ActionName = "Details" ControllerName = "Employee" In the second case your parameters to ActionLink are ActionName = "Index" ControllerName = "Employee" These parameters are then matched against your routes one by one. In the first case there is a match against your third route (url: "Employee/Details") In the second case there is a mat

Categories : Asp Net Mvc

MVC5 Log Off link fails from different Areas
The right place is within the Html.BeginForm(...) parameters: using (Html.BeginForm("LogOff", "Account", new { area = "" }, FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))

Categories : Asp Net Mvc

Ignore invalid url parameters
Add this in your web.config. You can either redirect to an Error page or your home page. <customErrors mode="On" defaultRedirect="~/Home/Index" /> And also check this answer: How can I properly handle 404 in ASP.NET MVC?

Categories : Asp Net Mvc

Using reference not found in HomeController
It's probable that in the Web.config inside your views folder there is an explicit reference to the Amazon.S3 library, but do you have a project reference for it? Check the references folder in your project and make sure that a reference exists.

Categories : Asp Net Mvc

CKEditor image dialog is failed
Check the "Network" tab in your browser for HTTP 404 errors. It looks like the file that contains Image Dialog definition is not available. Either it is not present (e.g. has been accidentally removed) or you have some weird url rewrite issues.

Categories : Asp Net Mvc

OWIN OAuth 2.0 Authorization Server
You need to secure your web api project, and handle in your mvc project , unauthorized responses from your web api service. For call your web api, you need to call first to your authorization server, get the bearer token and include the header in your subsequent requests to your web api service.

Categories : Asp Net Mvc

MVC 6 View Components
View components are definitively great and it's certainly an improvement. The one big improvement is that you can run asynchronous operations on view components where it wasn't possible with child actions. More information available here: Exciting Things About ASP.NET vNext Series: MVC View Components For donut caching, there are two separate issues filed that you can comment/track: #1232 and

Categories : Asp Net Mvc

MVC Kendo Combobox selected item value?
Instead of binding the combo box to enum bind it to object of key, value pair. Also define the "DataTextField and DataValueField" to get proper value of selected element. @(Html.Kendo().ComboBoxFor(model => model.IsPerson) .Placeholder("----- Select -----") .DataTextField("Value") .DataValueField("Key") .DataSource(source => source.Read(read => read.Action("MyActionMethod", "Controll

Categories : Asp Net Mvc

Is it possible to self-host the asp.net mvc application without the use of IIS?
You could consider using an OWIN self hosted application - see Use OWIN to Self-Host ASP.NET Web API 2 There's also the option of IIS Express if you want something more lightweight.

Categories : Asp Net Mvc

Handle SignalR constructor exceptions
Your best bet for handling exceptions thrown from a Hub constructor is probably by providing your own IHubActivator. Here is an example of how you can replace SignalR's IHubActivator. In that example the purpose for replacing IHubActivator was to use Simple Injector to activate hubs, but the same principle applies if you just want to handle/log any exceptions thrown during Hub construction.

Categories : Asp Net Mvc

Is this thread safe about RequestLifetimeHttpModule: ILifetimeScopeProvider
The only place that the method is called is in the constructor of RequestLifetimeScopeProvider, which in turn is only called by the AutofacDependencyResolver. As you can see on line 130, this is called in a singleton pattern, so there is no way it can be instatiated more than once per application start.

Categories : Asp Net Mvc

WebImage maximum size, file formats allowed etc
First: Maximum file size define on the WebServer level. So if you want to change it the best way for whole application is to change it in Web.config, maxRequestLength. Ex: <system.web> <compilation debug="true" targetFramework="4.5" /> <httpRuntime targetFramework="4.5" maxRequestLength="2147483647" executionTimeout="1600" requestLengthDiskThreshold="2147483647" /> &

Categories : Asp Net Mvc

AddBindings in Ninject and null repository in Controller class
I would start by removing the constructor to ProductController that has no parameters. This will force ninject to use the constructor with IProductsRepository. As for the binding part, we have the binding taking place inside the NinjectWebCommon.cs file. Here is our sample: public static class NinjectWebCommon { private static readonly Bootstrapper Bootstrapper = new Bootstrappe

Categories : Asp Net Mvc

MVC5 application with areas and subfolders within the controller folder
Your question isn't entirely clear, but I'll try to cover the bases. If your problem is with generating the right URL with something like Html.ActionLink, you need to pass your Area as route param. For example: @Html.ActionLink("Foo", "FooAction", "FooController", new { Area = "FooArea" }) Next, the namespace helps to restrict a particular route to an area/controller, etc., but it doesn't work

Categories : Asp Net Mvc

Stream Html document in a new page ASP.NET MVC
You need to specify a Content-Disposition header: Response.AppendHeader("Content-Disposition", "inline; filename=" + document.FileName); return File(document.File, document.MimeType); Also, I think you're looking for target="_blank". The attribute target="blank" will open in a window/tab named internally as "blank", and any further clicks will reload that window/tab instead of popping a new win

Categories : Asp Net Mvc

submit returns model as null in MVC 4
just a quick question, are you using foreach for the loop? if so use the normal, try with this for(int index=0; index < Model.Emplist.Count; index++) { @Html.HiddenFor(m => Model.Emplist[index].ID) @Html.EditorFor(m => Model.Emplist[index].Name) }

Categories : Asp Net Mvc

DataTable Transfer to View
You need a ViewModel. public class CustomerModel { public string PropertyAddress { get; set; } } var vm = new List<CustomerModel>(); foreach (var item in dtFindResults) { vm.Add(new CustomerModel { PropertyAddress = /* value from DataSet */ }); } return View(vm); Finally, your DataSet should come from a separate concern like a Repository. This repository should return a list of

Categories : Asp Net Mvc

ViewModel of Partial View Not Binding to that of main ViewModel after loading via AJAX
When you post to an action, the only parts that get filled by the modelbinder are the fields and data that were posted. If you're losing your services, then you need to provide fields in your form to hold on to that data during the post. For example, in whatever HTML is returned by your AJAX, you'd need to include something like a hidden input for each of the properties on Service: @Html.HiddenF

Categories : Asp Net Mvc

EPiServer 7 namespace for Locate() isn't resolving
Looks like he just uses a factory to get IContentRepository and forgot to mention to. So to just get the same functionality you can use the ServiceLocator to get the IContentRepository and then get all children for your page: var service = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentRepository>(); var pages = service.GetChildren<NewsArticle>(currentPage.Paren

Categories : Asp Net Mvc

ASP.NET MVC Session Expiring
You are setting incorrect attribute in your web.config. Instead of setting: <forms timeout="480" ... /> Specifies the time, in integer minutes, after which the cookie expires. you should set: <sessionState timeout="480" ... /> Specifies the number of minutes a session can be idle before it is abandoned.

Categories : Asp Net Mvc

What is the benefit to make encoderType to AntiXssEncoder in a MVC application?
It's setting full control over input values. When string has some malicious codes antixss library drops it to protect. http://haacked.com/archive/2010/04/06/using-antixss-as-the-default-encoder-for-asp-net.aspx/

Categories : Asp Net Mvc

Application_End fired in Debug Session after Code Rebuild - ASP.NET MVC
Your question is a little unclear - when you say making a code change when debugging, do you mean using the Edit and Continue feature? So you're making changes to the code while in a debug session? Either way I would have thought this is expected behaviour. If you change your code, the application would be unloaded and re-loaded which would naturally cause your session state to be lost. What beha

Categories : Asp Net Mvc

session timeout not working in mvc
Session timeout has nothing to do with authentication timeout - an InProc session is held in memory whereas the authentication token is a cookie which contains an expiry date/time. What you would have to do is force the expiration of the authentication ticket in the Session_Ended event in the global.asax - see this answer on how to do that as it's not just as simple as calling FormsAuthentication

Categories : Asp Net Mvc

IIS 6 URL Redirection
URLs with an extension (i.e. *.aspx) bypass the MVC routing entirely, and are instead served by IIS directly. That's why adding stuff to Global.asax does nothing; Global.asax is never hit. Instead, you will need to handle the rewrite at the IIS level, but IIS6 has no built-in support for rewriting URLs. There's a third-party plugin (third-party but free and open-source) to enable rewrite support.

Categories : Asp Net Mvc

Bind inputs to Dictionary in ViewModel
I think i find nice way of binding dictionary and it's actually what you need in your situation. In ASP.NET MVC 4, the default model binder will bind dictionaries using the typical dictionary indexer syntax property[key]. If you have a Dictionary<string, string> in your model, you can now bind back to it directly with the following markup: <input type="hidden" name="MyDictionary[MyKey]

Categories : Asp Net Mvc

Does @Html.Editfor use data bind
They have mentioned on their page Returns an HTML input element for each property in the object that is represented by the ..... Here they are saying that @Html.EditFor is available for each property of the model. Its not same as its using foreach. This is indeed data binding.

Categories : Asp Net Mvc

unit test user.identity.getuserid asp.net mvc
I've been struggeling with mvc unit test my self, while there are known techniques to improve testability of your mvc application, most of the projects I worked on are sadly not following them. So I decided to start this project to help me and others who love to unit test their mvc application. Please take a look at: https://github.com/ibrahimbensalah/Xania.AspNet.Simulator. Here is an example un

Categories : Asp Net Mvc

Can I have Multiple Get Methods in ASP.Net Web API controller
Basically you cannot do that, and the reason is that both methods have same name and exactly the same signature (same parameter number and types) and this will not compile with C#, because C# doesn't allow that. Now, with Web API, if you have two methods with the same action like your example (both GET), and with the same signature (int, User), when you try to hit one of them from the client side

Categories : Asp Net Mvc

Send emails using gmail after Oauth 2.0 in MVC Application
You can Use Postal which is very handy and easy to use ,to send emails Controller dynamic email = new Email("Email"); email.To = UserName; email.FirstName = FName; email.LastName = LName; email.Send(); Then in your View Email @{ Layout = null; } To: @ViewBag.To From: Example lolcats@website.com Subject: blah blah Hello @ViewBag.FirstName, Your Text......... This is auto generated email pl

Categories : Asp Net Mvc

Telerik reports without trdx files
The serviceUrl expects to be routed to the Telerik Reporting Web API controller. The current value you use /api/reports/ is Telerik's default name for this controller. The documentation details how to implement the Web API controller pretty well. You'll find that here http://www.telerik.com/help/reporting/telerik-reporting-rest-host-http-service-using-web-hosting.html and here http://www.telerik.c

Categories : Asp Net Mvc

Asp.net with MVC Partial view and models
What I did is separate the view to partial views, so the main view will accept (MainModel) as its model and then the partials will each accept a different model from within the (MainModel), for example: //index.cshtml @model mvc.Models.MainModel @using (Html.Beginform("SaveData","Home")) { @html.kendo().panelbar() .items() { items.add() .content(@Html.Pa

Categories : Asp Net Mvc

Using a HtmlHelper in MVC 5
Your method should be something like using System; using System.Linq.Expressions; using System.Web.Mvc; using System.Web.Mvc.Html; namespace YourAssembly.Html { public static class DisplayHelper { public static MvcHtmlString DisplayWithIdFor<TModel, TValue>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TValue>> expression, string wrapperTag = "div")

Categories : Asp Net Mvc

MVC 4.5 - simplest authentication
In the Web.config file (in the root of your web project) you need to configure the forms authentication, example: <system.web> ... <authentication mode="Forms"> <forms loginUrl="∼/Account/Login" timeout="2880" /> </authentication> Check if that configuration is OK.

Categories : Asp Net Mvc

Using automapper with PagedList.mvc
I would create a PagedList<Item> manually and then map to a PagedList<ItemViewModel>: [HttpGet] public ActionResult Index(int page = 1) { int pageSize = 20; var vm = new ItemListViewModel(); var items = new PagedList( db.Items.OrderBy(i => i.ItemId), page, pageSize); var viewModels = Mapper.Map<PagedList<Item>, PagedList<ItemLis

Categories : Asp Net Mvc

viewbag returning null in view and not in controller
ViewBag can only be used to provide values from Controller to View in the same request. When you use 'Redirect(...)' there is another request coming from the browser, so your ViewBag value does not exist in that next request. You can use 'TempData' to store data that survives one request. I'm not sure if you can use it in your code because it is hard to tell the full scope from just a few lines t

Categories : Asp Net Mvc

Html.DropdownList different Behaviour
Its not strange at all, and is the expected behavior. In the first example you are not binding your drop down to any property in you model. Internally the helper just builds <select name="Languages"> with the options based on your collection of SelectListItem and sets the value of select to the first item where Selected=true. In the second example, your using the overload where your trying

Categories : Asp Net Mvc




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.