|
|
Thanks. Already saw that.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I am trying to create a checkbox which AutoPostBack when a checkbox is clicked :
ex.
@Html.CheckBox("IncludeClosed", true, new { onChange = "this.form.submit()"})
but i get error:
Uncaught TypeError: Cannot read property 'submit' of null
and If I inspect my code in Developer tools in the browser this is returned:
<input checked="checked" id="IncludeClosed" name="IncludeClosed" onChange="this.form.submit()" type="checkbox" value="true" />input name="IncludeClosed" type="hidden" value="false"
modified 25-Jun-19 14:18pm.
|
|
|
|
|
Is your checkbox definitely inside a <form> tag? If not, then this.form will return null .
The extra hidden input is perfectly normal. The ASP.NET forums have an explanation:
When you submit a form with a checkbox, the value is only posted if the checkbox is checked. So, if you leave the checkbox unchecked then nothing will be sent to the server when in many situations you would want false to be sent instead. As the hidden input has the same name as the checkbox, then if the checkbox is unchecked you'll still get a 'false' sent to the server.
When the checkbox is checked, the ModelBinder will automatically take care of extracting the 'true' from the 'true,false'
If you absolutely want to avoid the extra hidden input you can create your own helper method, as discussed in this StackOverflow thread[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
So I discovered when I updated my CheckBox helper method to :
@Html.CheckBox("IncludeClosed", false, new { onChange = "this.IncludeClosed.submit()"})
This is my form:
@using (Html.BeginForm("Index","Chargeback",FormMethod.Get,new { id = "IncludeClosed"}))
but I get a new error:
Cannot read property 'submit' of undefined
modified 25-Jun-19 15:39pm.
|
|
|
|
|
Javascript doesn't create global variables for elements in your page. If you want to refer to an element by ID, you have to use the document.getElementById method[^].
@Html.CheckBox("IncludeClosed", false, new { onChange = "document.getElementById('IncludeClosed').submit()"})
But if your checkbox is outside of your form, it's not going to be sent back to the server. Only the input elements within the form will be submitted with the form.
You might be able to use the form attribute[^] to work around that. But it's not supported in any version of Internet Explorer or Microsoft Edge. If you need to support either of those browsers, you'll have to move the checkbox inside the form - at which point, your original code will start working.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
This approach gives me an error b/c document doesn't exist in the current context also if a submit it as a string then it doesn't recognize the function.
@Html.CheckBox("IncludeClosed", false, new { onChange = "document.getElementById('IncludeClosed').submit()"})
|
|
|
|
|
I figured it out I added the checkbox inside of the form like you suggested and it works:
@using (Html.BeginForm("Index", "Chargeback"))
{
@Html.CheckBox("IncludeClosed", false, new { onChange = "this.form.submit()" })
I am getting the result of true,false but I believe you mentioned how to solve this issue.
Thank you again.
|
|
|
|
|
I'm getting the following warnings when I compile my MVC5 app:
warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.Owin.Security.Cookies". Check to make sure the assembly exists on disk.
warning MSB3243: No way to resolve conflicgt between "Microsoft.Owin.Security.Cookies, Version=4.0.1.0, Culture=nuetral, PublicKeyToken=31bf3856ad364e35" and "Microsoft.Owin.Security.Cookies". Choosing "Microsoft.Owin.Security.Cookies, Version=4.0.1.0, Culture=nuetral, PublicKeyToken=31bf3856ad364e35" arbitrarily.
The assembly in question is a nuget package, and it exists in my local nuget repository, and the reference reflects the proper (nuget) path. My web config contains the following:
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0"/>
</dependentAssembly>
I'm at a loss. The app compiles with these two warnings, but seems to run fine (since it's evidently selecting the referenced assembly "arbitrarily".
I hate warnings. How do I resolve them?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
modified 26-Jun-19 6:53am.
|
|
|
|
|
My boss wants to start doing this.
I know I can create a new project and specify that I want unit tests, but he also brought up a nuget package called NuGet Gallery|Moq 4.12.0[^^]
Does anyone have any insight in this regard?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Quote: specify that I want unit tests, But the library that your boss brought is more for mocking, rather unit testing. If you don't need to mock the resources such as database connections, network requests, or other and external APIs, then I don't think Moq would be necessary at all a simple xUnit or NUnit would be suitable enough.
Quote: I know I can create a new project And then bring the entire code base in that new project? Doesn't seem legit, but you can easily add a new project in the solution, and connect that (new testing) project with your existing web application as a reference (MVC would be a dll). Then using the content from your MVC, you can run tests on them.
This mocking framework would come in handy where you would need to pass in the database connections, or other content that doesn't need to be there in testing environments; thus Moq.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Afzaal Ahmad Zeeshan wrote: And then bring the entire code base in that new project? Doesn't seem legit, but you can easily add a new project in the solution, and connect that (new testing) project with your existing web application as a reference (MVC would be a dll). Then using the content from your MVC, you can run tests on them.
When you create a MVC project with unit test turned on, it adds another class library project to your solution. Your app is referenced in the test project, but the test project isn't referenced in the class library. I don't know how it all works yet, or even if you can unit test anything other than controllers.
I had installed Moq thru nuget, and it completely screwed up my app. I had to manually remove it because trying to uninstall via nuget threw errors at me. It was a mess...
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Quote: When you create a MVC project with unit test turned on But you are not going to be using a new project, right? I might have misunderstood, but I thought your boss wanted you to integrate this in an existing project.
Quote: nuget threw errors at me. Yep, NuGet expects that build errors are not there, even if it had caused those errors!
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Afzaal Ahmad Zeeshan wrote: But you are not going to be using a new project, right? I might have misunderstood, but I thought your boss wanted you to integrate this in an existing project.
I created a template project that handles all the tedious user handling, environment awareness, and connection string construction (we have 20+ databases used by 19 apps that can be deployed to three environments on both classified and unclassified networks, which equates to at least 160 possible connection strings).
He wanted to add unit testing and mocking to the template so we'd already have it when we created a new solution. Unit testing wasn't a problem because I could specify that I wanted unit testing when I created the project (and it does work), but adding Moq freaked everything out.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I've never had a problem adding moq to a project.
|
|
|
|
|
I'm not sure how everything went so sideways. There were unstated dependencies in the package, and some of the referenced dlls couldn't be found - it was a mess. When I tried to uninstall it, I got errors in nuget, and had to manually remove everything. :/
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
how to get oulook current user context in adaptive cards and actionable messages onclick of comment/like in email?
|
|
|
|
|
|
I have an Asp.Net Web API2 running on a Windows Server 2012R2 here at the office.
Now, we set up another server running Window Server 2019 Standard and I am attemping to host the API there but I cannot connect to it. When I attempt to reach a test controller at"http://192.168.50.153:8092/api/test/test" I get a 404.
Again, this is working on another server. I just can't connect to it on this one.
Do I need to open a port? I did, but that doesn't see to make a difference.
I'm not really sure how to debug this. Could use some help.
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
If it's hosted in IIS, try opening the URL in a browser running on the server. You should get a lot more detail in the error message.
You could also try IIS failed request tracing:
Troubleshooting Failed Requests Using Tracing in IIS 8.5 | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Well, I WAS getting a reponse on the server in a browser with http://192.168.50.153:65078/api/test/test
Now, I get a 404.
That Tracing looks like a LOT of work.
Quick question... to install in IIS all I did was open my API project folder, zip everything up, unzip
on the server, and point IIS to it. This worked on the previous server. Is this the way to do this? Can you point me to any resources on installing a Web API on a server?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
That should work, assuming the relevant IIS features are installed, and you're not using .NET Core.
If you're not getting a detailed error message when you access the page on the server, then Failed Request Tracing is the way to go. It's really not that difficult to set up.
- Enable FRT:
- Open IIS Manager and select your site;
- On the right-hand side, click on "Failed request tracing..." under "Configure";
- Tick the "Enabled" box;
- Click "OK";
- Configure a tracing rule for 404 errors:
- In the main pane, double-click "Failed request tracing rules";
- On the RHS, click "Add...", and set up the rule:
- All content - Next
- Status codes: 404 - Next
- Leave all providers ticked - Finish
- Generate an error and view the log file:
- Open the URL which isn't working in a browser;
- Open the
%systemdrive%\inetpub\logs\FailedReqLogFiles\... folder in Windows Explorer; - Open the XML file in Internet Explorer;
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks, I'll try it.
The message I get in the browser on the server is something like "File or folder" not found.
Not looking at it right now.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Thanks Richard - why the caveat about
Richard Deeming wrote: and you're not using .NET Core. I am getting an invalid web.config error and will use the above as another check.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
|