locked
Keeping the data in the field in Razor Syntax RRS feed

  • Question

  • User1104256871 posted

    Hello.  

    I am working on a edit page and have problem with trying to keep data in one of my notes fields. I can search for the all the data in the table.  I get all of the data in that field, but the text box is empty.   I am able to display the data in read only mode but not keep it in the notes field to add on to it.  I need to be able to add data to the field and just update it. Now I have to type all of the data over again and then save it. I know it is how I getting the data, but I don't know where to look.  Any assistance would be appreciated

    @{
        
        Layout = "~/_Layout.cshtml";
        var id = Request["id"];
        var ud = Request["ud"];
        var query = " ";
        var db = Database.Open("Tester03DB");
        
    
        
        var UserID = "";
        var Issue = "";
        var Notes = "";
        
    
          
    
        if(id.IsEmpty())
        {
            Response.Redirect("~/frms2/notelist.cshtml");
        }
        else
        {
            query = "SELECT * FROM tblIssues WHERE issueID=@0";
            var item = db.QuerySingle(query, id);
            
         Issue = item.Issue.Trim();
         Comments = item.Comments.Trim();
                
        }
          if(IsPost && Validation.IsValid()){
            var updatedQ = "UPDATE tblIssues SET UserID=@0,Notes=@1, WHERE IssueID=@2";
            db.Execute(updatedQ, userID, Notes,  id);
            Response.Redirect("~/frms2/notelist");
          }
      }  
    
    @{
         //selects the Users1
           var db2 = Database.Open("Tester03DB");
           var selectuser = "SELECT UserID, UserName FROM tblUsers";
           var selectedUser = db2.Query(selectuser);           
    }
    @{
            dynamic username = null;
             var db3 = Database.Open("Tester03DB");
             var sql3 = "SELECT * FROM tblUsers WHERE UserId  = @0";
            username = db2.QuerySingle(sql3, Request["ud"]);
       
    }
      
    
    <!DOCTYPE html>
    <script src="~/date/htmlDatePicker.js" type="text/javascript"></script>
    <link href="~/date/htmlDatePicker.css" rel="stylesheet">
    
    <html lang="en">
       <head>
      
    </head>
    <body>
      <h1>Modify an Issue</h1>
      @Html.ValidationSummary()
      <form method="post">
        <fieldset>
          <legend>Issue Information</legend>
        </p>
    
    <h3>Issue created by: @username.UserName </h3>
    
          <p><label for="Issue">Issue: @Issue</label></p>
          
           <p><label for="Notes">Notes (must be less than 250 Characters</label></p>
           <p>  <textarea name="Notes" cols="50" rows="5"></textarea>  </p>
    
          <p><input type="submit" name="buttonSubmit" value="Update Note" /></p>
        </fieldset>

    Thursday, August 25, 2016 2:36 PM

Answers

  • User-821857111 posted
    @{
        
        Layout = "~/_Layout.cshtml";
        var id = Request["id"];
        var ud = Request["ud"];
        var query = " ";
        var db = Database.Open("Tester03DB");
        
    
        
        var UserID = "";
        var Issue = "";
        var Notes = "";
        var Comments = "";
    
          
    
        if(id.IsEmpty())
        {
            Response.Redirect("~/frms2/notelist.cshtml");
        }
        else
        {
            query = "SELECT * FROM tblIssues WHERE issueID=@0";
            var item = db.QuerySingle(query, id);
            
         Issue = item.Issue.Trim();
         Comments = item.Comments.Trim();
         Notes = item.Notes.Trim()
        }
          if(IsPost && Validation.IsValid()){
            var updatedQ = "UPDATE tblIssues SET UserID=@0,Notes=@1, WHERE IssueID=@2";
            db.Execute(updatedQ, userID, Request["Notes"],  id);
            Response.Redirect("~/frms2/notelist");
          }
      }  
    
    @{
         //selects the Users1
           var db2 = Database.Open("Tester03DB");
           var selectuser = "SELECT UserID, UserName FROM tblUsers";
           var selectedUser = db2.Query(selectuser);           
    }
    @{
            dynamic username = null;
             var db3 = Database.Open("Tester03DB");
             var sql3 = "SELECT * FROM tblUsers WHERE UserId  = @0";
            username = db2.QuerySingle(sql3, Request["ud"]);
       
    }
      
    
    <!DOCTYPE html>
    <script src="~/date/htmlDatePicker.js" type="text/javascript"></script>
    <link href="~/date/htmlDatePicker.css" rel="stylesheet">
    
    <html lang="en">
       <head>
      
    </head>
    <body>
      <h1>Modify an Issue</h1>
      @Html.ValidationSummary()
      <form method="post">
        <fieldset>
          <legend>Issue Information</legend>
        </p>
    
    <h3>Issue created by: @username.UserName </h3>
    
          <p><label for="Issue">Issue: @Issue</label></p>
          
           <p><label for="Notes">Notes (must be less than 250 Characters</label></p>
           <p>  <textarea name="Notes" cols="50" rows="5">@Notes</textarea>  </p>
    
          <p><input type="submit" name="buttonSubmit" value="Update Note" /></p>
        </fieldset>
    


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 6, 2016 2:49 PM

All replies

  • User325035487 posted

    your query is not clear.

    same like u do this var selectuser = "SELECT UserID, UserName FROM tblUsers";

    selext the note u need to a variable for example var selectednote and do this

     <p>  <textarea name="Notes" cols="50" rows="5">@selectednote</textarea>  </p>
    

    Thursday, August 25, 2016 8:00 PM
  • User-2057865890 posted

    Hi Mark,

    In your code I did not find that where you assigned a value to Notes Text Area. So how it can display that data.

    So please visit the link below in which there is a complete example to how to edit data using Razor.

    Refer the example and make the necessary changes in your code to solve the issue.

    Introducing ASP.NET Web Pages - Updating Database Data

    http://www.asp.net/web-pages/overview/getting-started/introducing-aspnet-web-pages-2/updating-data 

    Regards

    Chris

    Friday, August 26, 2016 10:57 AM
  • User1104256871 posted

    Sorry if I wasn't that clear.  I had to "edit" the code because there is some specialized things in there.  I think my problem is the getting items in the this code. 

    <p>  <textarea name="Notes" cols="50" rows="5"></textarea>  </p>

    I can get the other fields but this doesn't populate.   I can save the data in there, but I cannot get it to populate back in the field. 

    Thursday, September 1, 2016 4:19 PM
  • User325035487 posted

    still not clear

    Friday, September 2, 2016 8:31 AM
  • User-2057865890 posted

    Hi Mark X,

    Declare a variable, retrieve data and populate this variable.

    @{
       var note = ... retrieve note data
    }
    

    Display data.

    <textarea name="Notes" cols="50" rows="5">
      @note
    </textarea>

    Best Regards,

    Chris

    Friday, September 2, 2016 8:50 AM
  • User1104256871 posted

    Thanks for the answer.  Here is what I have. 

    var note = "";  //declares Variable
    

    then I have

    note = item.note.Trim();  // brings up data 
    

    Saving the data

           var updatedQ = "UPDATE tblNotes SET Status=@0, note=@1 WHERE nID=@2";
           db.Execute(updatedQ, Status, note, id);

    Textarea 

    <p>  <textarea name="note" cols="50" rows="8">@note</textarea>
              @Html.ValidationMessage("genre")

    Still having a problem with getting data and saving data.  I know it is something simple, but just can't pinpoint it. 

    Tuesday, September 6, 2016 1:43 PM
  • User-821857111 posted
    @{
        
        Layout = "~/_Layout.cshtml";
        var id = Request["id"];
        var ud = Request["ud"];
        var query = " ";
        var db = Database.Open("Tester03DB");
        
    
        
        var UserID = "";
        var Issue = "";
        var Notes = "";
        var Comments = "";
    
          
    
        if(id.IsEmpty())
        {
            Response.Redirect("~/frms2/notelist.cshtml");
        }
        else
        {
            query = "SELECT * FROM tblIssues WHERE issueID=@0";
            var item = db.QuerySingle(query, id);
            
         Issue = item.Issue.Trim();
         Comments = item.Comments.Trim();
         Notes = item.Notes.Trim()
        }
          if(IsPost && Validation.IsValid()){
            var updatedQ = "UPDATE tblIssues SET UserID=@0,Notes=@1, WHERE IssueID=@2";
            db.Execute(updatedQ, userID, Request["Notes"],  id);
            Response.Redirect("~/frms2/notelist");
          }
      }  
    
    @{
         //selects the Users1
           var db2 = Database.Open("Tester03DB");
           var selectuser = "SELECT UserID, UserName FROM tblUsers";
           var selectedUser = db2.Query(selectuser);           
    }
    @{
            dynamic username = null;
             var db3 = Database.Open("Tester03DB");
             var sql3 = "SELECT * FROM tblUsers WHERE UserId  = @0";
            username = db2.QuerySingle(sql3, Request["ud"]);
       
    }
      
    
    <!DOCTYPE html>
    <script src="~/date/htmlDatePicker.js" type="text/javascript"></script>
    <link href="~/date/htmlDatePicker.css" rel="stylesheet">
    
    <html lang="en">
       <head>
      
    </head>
    <body>
      <h1>Modify an Issue</h1>
      @Html.ValidationSummary()
      <form method="post">
        <fieldset>
          <legend>Issue Information</legend>
        </p>
    
    <h3>Issue created by: @username.UserName </h3>
    
          <p><label for="Issue">Issue: @Issue</label></p>
          
           <p><label for="Notes">Notes (must be less than 250 Characters</label></p>
           <p>  <textarea name="Notes" cols="50" rows="5">@Notes</textarea>  </p>
    
          <p><input type="submit" name="buttonSubmit" value="Update Note" /></p>
        </fieldset>
    


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 6, 2016 2:49 PM