asp.net-mvc-5

pass a different model to the partial view

你。 提交于 2020-02-13 04:14:11
问题 I am trying to pass a different model to the partial view from a view. I have two separate controller actions for both of them and two different view models. But when I call the partial view from within the view it gives me the error The model item passed into the dictionary is of type 'Application.ViewModels.Model1ViewModel', but this dictionary requires a model item of type 'Application.ViewModels.PartialViewModel'. I am calling it like this: @Html.Partial("_CreateUniFunctionPartial") the

ASP.NET MVC 5 DropDownListFor not selected

我的梦境 提交于 2020-02-08 05:41:31
问题 I can't get a specific DropDownList to preselect my selected value in ASP.NET MVC 5. I use the same logic for several other DDLs and it works, but not for this one. Maybe some of you have an idea. This piece of code is inside my ASP.NET MVC 5 Razor View: @Html.DropDownListFor(x => x.SelectedDate, Model.SelectListDays, new { @class="newEntryDays"}) This is what the Watchlist says about my model IN THE VIEW HTML: The first option is 'selected' <option selected="selected" value="13.01.2014">Mo

Angular 6 Signalr with MVC 5

强颜欢笑 提交于 2020-02-07 03:46:06
问题 I am using angular 6 with my current project which is in mvc 5 , all other things are working perfect, the only problem i am facing in implementing SignalR, this is my signalr.service.ts code: export class SignalRService { dataReceived = new EventEmitter<myData>(); connectionEstablished = new EventEmitter<Boolean>(); private connectionIsEstablished = false; private _hubConnection: HubConnection; constructor() { this.createConnection(); this.registerOnServerEvents(); this.startConnection(); }

TextAreaFor Not Working When Using HtmlAttributes Overload

◇◆丶佛笑我妖孽 提交于 2020-02-06 16:54:46
问题 For some reasons, when I set my TextAreaFor style properties specifically the width property, it is not working, what I mean is the width is not changing, and the Id is not changing as well: @Html.TextAreaFor(model => model.AdminSetting.Style, new { htmlAttributes = new { @class = "form-control", @style = "width: 100%;", @id = "HelloWorld" } }) But if I remove the word htmlAttributes and change it to this then it working fine. I really wonder why: @Html.TextAreaFor(model => model.AdminSetting

MVC Model child object null on HTTP post

梦想的初衷 提交于 2020-02-03 05:39:12
问题 Hope someone can help me. I am new to MVC, coming from a winforms/console/vb6background. Apologies if this has already been answered, I am stuggling to understand how I can resolve the below issue. I have a view model : public class testvm { public int id { get; set; } public DateTime date { get; set; } public student studentID { get; set; } public testvm() { } public testvm (student s) { studentID = s; } } I am pre-populating the student child object of this ViewModel before it is passed to

MVC5 Identity/OWIN - Signout events

浪尽此生 提交于 2020-02-01 09:04:28
问题 How to detect all possible SignOuts? Is there a way to get some event when SignOut is made manually, by timeout and any other possible ways? I need to know when user authentication ends like i know that it starts when SingIn is called. I'm using both internal accounts and external (like Facebook). 回答1: I need a spot that i can initialize user session when user is already authenticated. Below is code that should do the job, i don't like it at all. I need to check session at each request to be

UnauthorizedAccessException when saving file, but can create a directory

吃可爱长大的小学妹 提交于 2020-01-30 09:23:10
问题 I'm trying to save a file to the disk but I get UnauthorizedAccessException. The error says I have to get the right permissions on the folder, and I've tried every possible user I can find but it doesn't work. Tried the following users Network Network Services IUSR IUSR_[Computername] And given the full rights without it working. What I find really strange is that I create a directory before I try to save the file and that works perfectly, it's when trying to save a file to that new directory

How can I limit the serving of a javascript file to only authenticated users?

為{幸葍}努か 提交于 2020-01-29 04:56:06
问题 I have a WebAPI 2 / AngularJS SPA application that uses Identity 2 for authentication. Locally my code stores a token for authentication. I would like to implement functionality that allows my application to request additional javascript for authenticated users after my initial index.html page has been downloaded. Is there a way I can make my server code give out the javascript files to only authenticated and authorized users? Something similar to the way a controller action method returns

How to pass ID to default value of another view

♀尐吖头ヾ 提交于 2020-01-26 03:27:10
问题 I have a list of incidents which can have associated jobs. I Have a separate views for incidents and jobs. From the incident index page I have the following link to create a new job for that incident: @Html.ActionLink("Create","Create", "Job", new { id = item.IncidentID }, null) which takes the incident ID from that field and loads the Job view. I want to pass the ID as a default value for creating a new job, so the job will be assigned the incident ID. I made this controller: public

ASP.NET MVC Custom RoleProvider cannot retrieve roles from database for username

て烟熏妆下的殇ゞ 提交于 2020-01-25 20:15:07
问题 i cant seem to find the right solution for the above issue. I keep getting System.NullReferenceException: Object reference not set to an instance of an object. i followed this guide http://techbrij.com/custom-roleprovider-authorization-asp-net-mvc The error message is from my custom roleprovider from the GetRolesForUser(string username) at line var user = _VisitorService.GetVisitors().FirstOrDefault(u => u.Username == username); The VisitorService works in the Controller but not in the