|
Member 15016778 wrote:
HAZID_Forms hazidFormToEdit = hazidForms.Find(id);
...
hazidFormToEdit = hazidFormViewModel.HAZID_Form;
hazidForms.Commit(); Your code finds the form with the specified ID, and stores it in a local variable.
It then overwrites the local variable with the value from the view-model, breaking any link between the variable and the repository.
It then tells the repository to commit the changes. But there are no changes to commit, because you've not updated anything that the repository knows about.
Instead of overwriting the local variable, you need to update the entity returned from the Find method using the properties of the view-model.
You'll also need to repopulate the view-model collections before displaying the view again.
private void PopulateLookups(HAZID_Form_View_Model hazidFormViewModel)
{
hazidFormViewModel.HAZID_Branch_Districts = hazidBranchDistricts.Collection();
hazidFormViewModel.HAZID_Hazard_Types = hazidHazardTypes.Collection();
hazidFormViewModel.HAZID_Risk_Severity_Types = hazidRiskSeverityTypes.Collection();
hazidFormViewModel.HAZID_Risk_Probability_Types = hazidRiskProbabilityTypes.Collection();
hazidFormViewModel.HAZID_Statuses = hazidStatuses.Collection();
hazidFormViewModel.HAZID_Persons = hazidPersons.Collection();
}
[HttpGet]
public ActionResult EditReport(int id)
{
HAZID_Forms hazidFormToEdit = hazidForms.Find(id);
if (hazidFormToEdit == null)
{
return HttpNotFound();
}
HAZID_Form_View_Model hazidFormViewModel = new HAZID_Form_View_Model();
hazidFormViewModel.HAZID_Form = hazidFormToEdit;
PopulateLookups(hazidFormViewModel);
return View(hazidFormViewModel);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult EditReport(HAZID_Form_View_Model hazidFormViewModel, int id)
{
HAZID_Forms hazidFormToEdit = hazidForms.Find(id);
if (hazidFormToEdit == null)
{
return HttpNotFound();
}
if (!ModelState.IsValid)
{
PopulateLookups(hazidFormViewModel);
return View(hazidFormViewModel);
}
hazidFormToEdit.HAZID_Status_Id = hazidFormViewModel.HAZID_Form.HAZID_Status_Id;
hazidFormToEdit.HAZID_Action_Taken = hazidFormViewModel.HAZID_Form.HAZID_Action_Taken;
...
hazidForms.Commit();
return RedirectToAction("ListReports");
}
NB: Don't use @Html.Raw(...) when displaying values in your view unless you expect the property to contain valid HTML which you want to include in your output. As it stands, your code is vulnerable to a persisted cross-site scripting (XSS) attack[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks soo much that makes since. I just thought i could copy the whole thing in one step but now i see that is not the case.
As for the raw i was once again not sure as I need to get the text from a different column based on the language.
If you know a better way i would appreciate any insight.
|
|
|
|
|
Hi,
My solution have 3 layers (Business class project, Data Class Project and Application (ASP.Net, C#)). I can build Business and Data Class project, but when i build solution my Visual studio freezes and not showing any result in Output. after 5 or 10 minutes will get pop up message "Visual studio stopped working" and restart visual studio. I tried the below solutions to sort this issue, but nothing did help me.
1) Deleted files from Temporary folders
1.1)C:\Users\<user name="">\AppData\Local\Temp\Temporary ASP.NET Files
1.2)C:\Users\<user name="">\AppData\Local\Microsoft\WebsiteCache
1.3) C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files
1.4) C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files
2) Repair Visual studio
3) Uninstall and Re-Install Visual studio
4) Delete the .SUO file
I Can build this solution in my Personnel laptop(Windows 7) but in my workstation(Windows 8) have this problem. I am using Visual Studio 2012.
Please help me to sort this issue.
|
|
|
|
|
You need to report the problem to Microsoft.
But the obvious question is, why are you using a version of Visual Studio from nine years ago, when VS2019 community edition is available for free?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Did you try the latest versions of Visual Studio like 2017 or 2019? They have radical improvements right from the installer stage.
|
|
|
|
|
How do you get dynamically loaded tabs to work in ASP.Net Core MVC?
1. I have a simple Index.cshtml that uses bootstrap tabs to create two tabs from the a tags on the page. (To test out options, I first copied from https://qawithexperts.com/article/asp.net/bootstrap-tabs-with-dynamic-content-loading-in-aspnet-mvc/176)
2. There is a click event on each tab that uses $.ajax() to call the controller and then set the html of the appropriate div.
3. I have a model with one field, a string that is required.
4. I have the create view that Visual Studio created.
5. When I run it and click the first tab, the controller returns PartialView("FirstTabCreate") and loads into the div and everything looks great.
6. The problem is when clicking the "Create" button.
7. The controller method checks if IsValid on the ModelState. If not, here is where I run into a problem. If I return the partial view and the model that was passed in I see my validation errors as expected but because I returned the partial view, I lose my tabs. If I return the main view (Index) then the javascript reloads my partial view and has lost the ModelState at that point.
I am not sure what to return so that this works. I have seen lots of examples online that use dynamically loaded tabs but none of them have models or validation.
Code below: Index Page
@model FirstTab
<!-- Tab Buttons -->
<ul id="tabstrip" class="nav nav-tabs" role="tablist">
<li class="active">
<a href="#FirstTab" role="tab" data-toggle="tab">Submission</a>
</li>
<li>
<a href="#SecondTab" role="tab" data-toggle="tab">Search</a>
</li>
</ul>
<!-- Tab Content Containers -->
<div class="tab-content">
<div class="tab-pane active" id="FirstTab">
</div>
<div class="tab-pane fade" id="SecondTab">
</div>
</div>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script>
$('#tabstrip a').click(function (e) {
e.preventDefault();
var tabID = $(this).attr("href").substr(1);
$(".tab-pane").each(function () {
console.log("clearing " + $(this).attr("id") + " tab");
$(this).empty();
});
$.ajax({
url: "/@ViewContext.RouteData.Values["controller"]/" + tabID,
cache: false,
type: "get",
dataType: "html",
success: function (result) {
$("#" + tabID).html(result);
}
});
$(this).tab('show');
});
$(document).ready(function () {
$('#tabstrip a')[0].click();
});
</script>
FirstTabCreate View
@model WebApplication1.Models.FirstTab
<h4>FirstTab</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="FirstTabCreate">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="FirstName" class="control-label"></label>
<input asp-for="FirstName" class="form-control" />
<span asp-validation-for="FirstName" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" />
</div>
</form>
</div>
</div>
<div>
<a asp-action="Index">Back to List</a>
</div>
Model
using System.ComponentModel.DataAnnotations;
namespace WebApplication1.Models
{
public class FirstTab
{
[Required()]
public string FirstName { get; set; }
}
}
Controller
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System.Diagnostics;
using WebApplication1.Models;
namespace WebApplication1.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
public ActionResult FirstTab()
{
return PartialView("FirstTabCreate");
}
public ActionResult FirstTabCreate(FirstTab model)
{
if (!ModelState.IsValid)
{
return View("FirstTabCreate", model);
}
return Content("Success");
}
public ActionResult SecondTab()
{
return PartialView("_SecondTab");
}
}
}
|
|
|
|
|
|
Thanks, this does work but it does not solve my issue. Doing this essentially causes the form validation to happen all client side and so my Controller method does not get called. One of the business requirements is to log validation errors in the database, which I was doing in the Controller method when ModelState was not valid.
I'll look to see if there is a way to get all validation errors client side so that I can still log them in the db. It just seems like there should be an easier way to do tabs.
|
|
|
|
|
Client-side validation prevents a costly round-trip to the server, and reduces the number of times the server code has to run just to reject the request as invalid.
If you log every single validation error, then unless you're very lucky with your users, I suspect you're going to end up with a "validation errors" database that grows by hundreds of gigabytes every day.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Speed is an important part of this data entry app and so they want to know who keeps making the same mistakes over and over. For example, who keeps forgetting to fill in a phone number. This way they can train users to be more efficient.
So, I get your point, but no, it won't be nearly that bad.
We actually are replacing a Java based web app and the current table for validation errors is big, but not too big.
|
|
|
|
|
Hi,
Failed to open crystal report in browser in ASP.Net and debugging shows some reference error.
Tried many solution but failed.
Thanks & Kind Regards
Mohammad Salmani
|
|
|
|
|
There's a secret error somewhere in your secret code. You need to fix that.
Seriously, how do you expect anyone to be able to help you if you won't show the relevant parts of your code, or even provide the full error message?!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I am getting the below errors.
Uncaught ReferenceError: bobj is not defined
GEThttp://localhost:82/aspnet_client/system_web/2_0_50727/crystalreportviewers13/js/crviewer/crv.js
GEThttp://localhost:82/aspnet_client/system_web/2_0_50727/crystalreportviewers13/js/crviewer/crv.js
tried many solution available on google
Thanks & Regards
Mohammad Salmani
|
|
|
|
|
Crystal Reports is not installed properly. There are lots of hits on Google for that error message. For example:
How do I resolve "bobj is undefined" issue? | SAP Blogs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
I set the cache provider below, but the Add method never called... Only several Get calls I receive...
Any idea why?
public class MyCacheProvider : OutputCacheProvider
{
public override object Add(string key, object entry, DateTime utcExpiry)
{
return entry;
}
public override object Get(string key)
{
return null;
}
public override void Remove(string key)
{
}
public override void Set(string key, object entry, DateTime utcExpiry)
{
}
}
"The only place where Success comes before Work is in the dictionary." Vidal Sassoon, 1928 - 2012
|
|
|
|
|
To send emails from an (old) asp.net website I use the following code :
-------
Protected Sub SendMail(sender As Object, e As System.EventArgs)
Try
Dim smtpSection As SmtpSection = CType(ConfigurationManager.GetSection("system.net/mailSettings/smtp"), SmtpSection)
Dim smtp As New SmtpClient
smtp.Host = smtpSection.Network.Host
smtp.EnableSsl = smtpSection.Network.EnableSsl
smtp.UseDefaultCredentials = smtpSection.Network.DefaultCredentials
smtp.Port = smtpSection.Network.Port
'solution 1 does not work !
'Dim networkCred As NetworkCredential = New Net.NetworkCredential(smtpSection.Network.UserName, smtpSection.Network.Password)
'smtp.Credentials = networkCred
'solution 2 does not work !
'Dim networkCred As New Net.NetworkCredential(smtpSection.Network.UserName, smtpSection.Network.Password)
'smtp.Credentials = networkCred
'solution 3 does work !!!
smtp.Credentials = New Net.NetworkCredential("yyyyyy@xxxxxx.com", "zzzzzz")
Using mm As New MailMessage(smtpSection.From, txtTo.Text.Trim())
mm.Subject = txtSubject.Text.Trim()
mm.Body = txtBody.Text.Trim()
mm.IsBodyHtml = False
TextBox2.Text = smtpSection.Network.UserName
TextBox3.Text = smtpSection.Network.Password
TextBox4.Text = smtpSection.Network.Host
TextBox5.Text = smtpSection.Network.Port
TextBox6.Text = smtpSection.Network.EnableSsl
TextBox7.Text = smtpSection.Network.DefaultCredentials
TextBox8.Text = smtpSection.From
TextBox9.Text = txtTo.Text.Trim()
smtp.Send(mm)
End Using
Catch error_t As Exception
TextBox1.Text = error_t.ToString
End Try
End Sub
-------
The web.config section contains this :
-------
<smtp deliveryMethod="Network" from="yyyyyy@xxxxxx.com" >
<network
host="smtp-auth.mailprotect.be"
port="2525"
userName="yyyyyyyy@xxxxxxxx.com "
password="zzzzzz"
defaultCredentials="false"
enableSsl="false"
/>
</smtp>
------
The namespaces loaded are :
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Net.Mail" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.Net.Configuration" %>
Solution 3 works fine but I don't like to show passwords in a page.
When using solution 1 or 2 the mailserver replies it does not relay, so apparently the credentials are not retrieved work properly.
All the other parameters do show properly in the textboxes I designed to test this sub.
Does anyone have a suggestion ?
Thanks.
Philippe Caron
|
|
|
|
|
Two things. ASP.NET code always executes on the server, never the client. That code will never be shown as part of "a page".
The first two attempts you show as "does not work" are because you're making assumptions about what those smtpSection.Network.UserName and smtpSection.Network.Password properties are returning. I would be willing to bet they don't return anything, so you're creating a NetworkCredential with blank username and password.
How do you tell? One word: debugger. Set a breakpoint on the line that creates the NetworkCredential and examine the values of UserName and Password. Chances are good those values are not what you think they are.
|
|
|
|
|
You shouldn't need any of that code. The SmtpClient will initialize itself based on the settings in the web.config file automatically.
The SmtpClient constructor[^] calls the Initialize method[^], which reads the settings from the config file.
If it's not working, then you need to debug your code to see what settings are actually being read from your config file.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Store Dataset into session variable
|
|
|
|
|
Is that an instruction or a proud boast?
|
|
|
|
|
I look at it as a project manager trying to give direction to a team member however inadvertently instead of typing in Microsoft Teams ended up submitting a new post in CodeProject.
|
|
|
|
|
Is this some kind of spam? If not, I'm sorry, but it definitely looks like it LOL.
|
|
|
|
|
Any one please explain the REDUX.
|
|
|
|
|