Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing c# public property in javascript

Is there any way to access the C# public properties in javascript?

For e.g. if there is following property in C# code:

public int MyProperty { get; set; }

Could this property be accessed in javascript file?

like image 595
Mrudang Vora Avatar asked Dec 11 '13 16:12

Mrudang Vora


People also ask

How to access the C drive of remote machines?

A lot of developers and net admins use them for accessing the C drive of remote machines. To access this share you need to know the local mchines password for Administrator or another user with rights.

Why can’t I access C drive in Windows 10?

Why C drive access is denied in Windows 10? In general, there are mainly 2 reasons that you cannot access C drive. The first is you do not have the privilege of accessing to this partition. And the second is that there may be bad sectors on the C drive.

What happens when C drive access is denied?

When you are denied to access C drive, you cannot access, change, save, or delete files and folders. Why C drive access is denied in Windows 10? In general, there are mainly 2 reasons that you cannot access C drive.

How to remotely open the C $admin share on Windows 10?

After rebooting, try to remotely open the C$ admin share on a computer running Windows 10. Log in using an account that is a member of the local Administrators group. A File Explorer window should open with the contents of the C:\ drive. Note. After that, other Windows 10 remote management functionality will become available.


1 Answers

there are several ways

<script>
var prop = <%=MyProperty %>;
</script>

using hidden fields

html:

<input id="hiddenF" type="hidden" runat="server" />

In .cs behind:

protected void Page_Load(object sender, EventArgs e)
{
    hiddenF.Value = MyProperty;
}

then getting the value via getElementById().Value

using ASP.NET MVC razor engine passing a model

<script>
var prop = @Model.MyProperty;
</script>
like image 191
theLaw Avatar answered Oct 01 '22 00:10

theLaw