Click here to Skip to main content
15,440,179 members
Home / Discussions / ASP.NET
   

ASP.NET

 
Questionncaught ReferenceError:System is not defined at (index):18 dx.light.css:1 Failed to load resource:the server responded with a status of 404(Not Found) Pin
Member 146901009-Jul-21 7:15
MemberMember 146901009-Jul-21 7:15 
AnswerRe: ncaught ReferenceError:System is not defined at (index):18 dx.light.css:1 Failed to load resource:the server responded with a status of 404(Not Found) Pin
SeeSharp29-Jul-21 7:38
MemberSeeSharp29-Jul-21 7:38 
JokeEste site aceita link? Pin
Ronaldo Luis Gonçalves6-Jul-21 3:37
MemberRonaldo Luis Gonçalves6-Jul-21 3:37 
AnswerRe: Este site aceita link? Pin
SeeSharp29-Jul-21 8:05
MemberSeeSharp29-Jul-21 8:05 
QuestionHow to Upgrade Publish website page in latest version at Visual Studio 2012 Pin
Robymon4-Jul-21 0:39
MemberRobymon4-Jul-21 0:39 
AnswerRe: How to Upgrade Publish website page in latest version at Visual Studio 2012 Pin
Richard Deeming4-Jul-21 21:36
mveRichard Deeming4-Jul-21 21:36 
QuestionHTTPPOST of EditReport not comiting data to database Pin
Carl Cummings (Canada)2-Jul-21 17:34
professionalCarl Cummings (Canada)2-Jul-21 17:34 
AnswerRe: HTTPPOST of EditReport not comiting data to database Pin
Richard Deeming4-Jul-21 21:34
mveRichard Deeming4-Jul-21 21:34 
Member 15016778 wrote:
C#
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.
C#
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);
    }

    // Copy the properties from the view-model to the entity:
    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

GeneralRe: HTTPPOST of EditReport not comiting data to database Pin
Carl Cummings (Canada)5-Jul-21 2:02
professionalCarl Cummings (Canada)5-Jul-21 2:02 
QuestionVisual Studio Freezes during build solution Pin
Robymon1-Jul-21 22:37
MemberRobymon1-Jul-21 22:37 
AnswerRe: Visual Studio Freezes during build solution Pin
Richard Deeming1-Jul-21 23:15
mveRichard Deeming1-Jul-21 23:15 
AnswerRe: Visual Studio Freezes during build solution Pin
Deepak Vasudevan13-Sep-21 21:49
MemberDeepak Vasudevan13-Sep-21 21:49 
QuestionASP.Net Core MVC - Validation Summary not working with bootstrap tabs and dynamically loaded content Pin
SeeSharp223-Jun-21 9:58
MemberSeeSharp223-Jun-21 9:58 
AnswerRe: ASP.Net Core MVC - Validation Summary not working with bootstrap tabs and dynamically loaded content Pin
Richard Deeming23-Jun-21 21:39
mveRichard Deeming23-Jun-21 21:39 
GeneralRe: ASP.Net Core MVC - Validation Summary not working with bootstrap tabs and dynamically loaded content Pin
SeeSharp224-Jun-21 2:21
MemberSeeSharp224-Jun-21 2:21 
GeneralRe: ASP.Net Core MVC - Validation Summary not working with bootstrap tabs and dynamically loaded content Pin
Richard Deeming24-Jun-21 3:54
mveRichard Deeming24-Jun-21 3:54 
GeneralRe: ASP.Net Core MVC - Validation Summary not working with bootstrap tabs and dynamically loaded content Pin
SeeSharp224-Jun-21 4:16
MemberSeeSharp224-Jun-21 4:16 
QuestionCrystal Report Issue in ASP.Net 2010. Pin
Mohammad Salmani8-Jun-21 20:43
MemberMohammad Salmani8-Jun-21 20:43 
AnswerRe: Crystal Report Issue in ASP.Net 2010. Pin
Richard Deeming8-Jun-21 21:31
mveRichard Deeming8-Jun-21 21:31 
GeneralRe: Crystal Report Issue in ASP.Net 2010. Pin
Mohammad Salmani8-Jun-21 22:36
MemberMohammad Salmani8-Jun-21 22:36 
GeneralRe: Crystal Report Issue in ASP.Net 2010. Pin
Richard Deeming8-Jun-21 22:51
mveRichard Deeming8-Jun-21 22:51 
GeneralRe: Crystal Report Issue in ASP.Net 2010. Pin
Mohammad Salmani10-Jun-21 4:11
MemberMohammad Salmani10-Jun-21 4:11 
QuestionOutputCacheProvider... Pin
Kornfeld Eliyahu Peter19-May-21 22:29
professionalKornfeld Eliyahu Peter19-May-21 22:29 
Questionaspnet credentials from web.config Pin
philippegent8-May-21 2:14
Memberphilippegent8-May-21 2:14 
AnswerRe: aspnet credentials from web.config Pin
Dave Kreskowiak8-May-21 4:58
mveDave Kreskowiak8-May-21 4:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.