2
Answers

How to get checkbox status and data value [MVC]

Bryan Gomez

Bryan Gomez

7y
152
1
How to get the checkbox status and data value from my table in HTML? I want to get the @myJob.so_no.
 
Here's my view:
  1. <table class="table table-striped table-hover table-condensed" id="myJobTable">  
  2.                     <thead class="thead-dark">  
  3.                         <tr>  
  4.                             <th scope="col">#</th>  
  5.                             <th scope="col"></th>  
  6.                             <th scope="col">Date</th>  
  7.                             <th scope="col">SO No</th>  
  8.                             <th scope="col">Serial</th>  
  9.                             <th scope="col">Status</th>  
  10.                             <th scope="col">Technician</th>  
  11.                         </tr>  
  12.                     </thead>  
  13.                     @foreach (MyJobAllocation myJob in Model.MyJob)  
  14.                     {  
  15.                         <tr>  
  16.                             <td>@myJob.row</td>  
  17.                             <td>  
  18.                                 <input type="checkbox" id="chk" />  
  19.   
  20.                             </td>  
  21.                             <td>@myJob.date</td>  
  22.                             <td>@myJob.so_no</td>  
  23.                             <td>@myJob.serial</td>  
  24.                             <td>@myJob.status</td>  
  25.                             <td>@myJob.technician</td>  
  26.                         </tr>  
  27.                     }  
  28.                 </table> 
 And for my script:
I'm  trying to print a simple alert if my function is working. But it doesn't.
  1. function asign_to() {  
  2.     var table = document.getElementById("myJobTable");  
  3.     var value_check = "";  
  4.     for (var i = 0; i < table.rows.length; i++) {  
  5.         if ($('#chk')[i].is(':checked')) {  
  6.             alert('You clicked me!');  
  7.         }  
  8.     }  

 Got this error:
  1.   TypeError: $(...)[i].is is not a function
Answers (2)
0
Scott Lysle

Scott Lysle

NA 28.5k 14.4m 16y

Per Ryan's suggestion:

using System;

using System.Collections.Generic;

using System.Text;

using System.IO;

using System.Security.AccessControl;

 

 

namespace FileSecurity

{

    class Program

    {

        static void Main(string[] args)

        {

                        try

            {

                string fileName = "c:\\temp\\somefile.txt";

 

                Console.WriteLine("Adding access control entry for "

                    + fileName);

 

                // Add the access control entry to the file.

                AddFileSecurity(fileName, @"SomeFolder\ AnotherFolder",

                    FileSystemRights.Read, AccessControlType.Deny);

 

                // Add the access control entry to the file.

                AddFileSecurity(fileName, @"SomeFolder\AnotherFolder",

                    FileSystemRights.Write, AccessControlType.Deny);

 

                //Console.WriteLine("Removing access control entry from "

                //    + fileName);

 

                //// Remove the access control entry from the file.

                //RemoveFileSecurity(fileName, @"SomeFolder\AnotherFolder",

                //    FileSystemRights.ReadData, AccessControlType.Allow);

 

                Console.WriteLine("Done.");

                Console.Read();

            }

            catch (Exception e)

            {

                Console.WriteLine(e);

                Console.Read();

            }

        }

 

        // Adds an ACL entry on the specified file for the specified account.

        public static void AddFileSecurity(string fileName, string account,

            FileSystemRights rights, AccessControlType controlType)

        {

           

 

            // Get a FileSecurity object that represents the

            // current security settings.

            System.Security.AccessControl.FileSecurity fSecurity =

            File.GetAccessControl(fileName);

 

            // Add the FileSystemAccessRule to the security settings.

            fSecurity.AddAccessRule(new FileSystemAccessRule(account,

                rights, controlType));

 

            // Set the new access settings.

            File.SetAccessControl(fileName, fSecurity);

 

        }

 

        // Removes ACL entry on file for the specified account.

        public static void RemoveFileSecurity(string fileName, string   

        account, FileSystemRights rights, AccessControlType controlType)

        {

 

            // Get a FileSecurity object that represents the

            // current security settings.

            System.Security.AccessControl.FileSecurity fSecurity =

            File.GetAccessControl(fileName);

 

            // Add the FileSystemAccessRule to the security settings.

            fSecurity.RemoveAccessRule(new FileSystemAccessRule(account,

                rights, controlType));

 

            // Set the new access settings.

            File.SetAccessControl(fileName, fSecurity);

 

        }

 

    }

}

 

Accepted
0
Scott Lysle

Scott Lysle

NA 28.5k 14.4m 16y

Per Ryan's suggestion:

using System;

using System.Collections.Generic;

using System.Text;

using System.IO;

using System.Security.AccessControl;

 

 

namespace FileSecurity

{

    class Program

    {

        static void Main(string[] args)

        {

                        try

            {

                string fileName = "c:\\temp\\somefile.txt";

 

                Console.WriteLine("Adding access control entry for "

                    + fileName);

 

                // Add the access control entry to the file.

                AddFileSecurity(fileName, @"SomeFolder\ AnotherFolder",

                    FileSystemRights.Read, AccessControlType.Deny);

 

                // Add the access control entry to the file.

                AddFileSecurity(fileName, @"SomeFolder\AnotherFolder",

                    FileSystemRights.Write, AccessControlType.Deny);

 

                //Console.WriteLine("Removing access control entry from "

                //    + fileName);

 

                //// Remove the access control entry from the file.

                //RemoveFileSecurity(fileName, @"SomeFolder\AnotherFolder",

                //    FileSystemRights.ReadData, AccessControlType.Allow);

 

                Console.WriteLine("Done.");

                Console.Read();

            }

            catch (Exception e)

            {

                Console.WriteLine(e);

                Console.Read();

            }

        }

 

        // Adds an ACL entry on the specified file for the specified account.

        public static void AddFileSecurity(string fileName, string account,

            FileSystemRights rights, AccessControlType controlType)

        {

           

 

            // Get a FileSecurity object that represents the

            // current security settings.

            System.Security.AccessControl.FileSecurity fSecurity =

            File.GetAccessControl(fileName);

 

            // Add the FileSystemAccessRule to the security settings.

            fSecurity.AddAccessRule(new FileSystemAccessRule(account,

                rights, controlType));

 

            // Set the new access settings.

            File.SetAccessControl(fileName, fSecurity);

 

        }

 

        // Removes ACL entry on file for the specified account.

        public static void RemoveFileSecurity(string fileName, string   

        account, FileSystemRights rights, AccessControlType controlType)

        {

 

            // Get a FileSecurity object that represents the

            // current security settings.

            System.Security.AccessControl.FileSecurity fSecurity =

            File.GetAccessControl(fileName);

 

            // Add the FileSystemAccessRule to the security settings.

            fSecurity.RemoveAccessRule(new FileSystemAccessRule(account,

                rights, controlType));

 

            // Set the new access settings.

            File.SetAccessControl(fileName, fSecurity);

 

        }

 

    }

}

 

0
Ryan Alford

Ryan Alford

NA 2.3k 891.7k 16y
you can set the permissions of the directory to not allow write access.  Then use code to programmatically change the permissions to allow the writing of the file, write the file, close the file, then restore the old permissions.