- Home
- Forum
- ASP.NET MVC - EJ 2
- how to put encrypt function in href link
how to put encrypt function in href link
Hi, I have create a .cs function to ecnrypt and decrypt parameter value that is pass thru rel='nofollow' href link.
For value that is pass using from data grid based on click details for each row, we use this kind of syntax (ex: ${DocNumber}). I can't figure out how to pass the value in my function because it makes the syntax wrong for rel='nofollow' href link. please find below my code for better understanding.
Not a valid syntax
usually, for hardcoded value, i just wrote the syntax as per below
onclick="location.rel='nofollow' href='/CTS/ScoringReport?IN_OUT=OUT&[email protected]("SEA", true)'
so, the question is, how to pass dynamic value( ${anyvaluefromgrid}) to the link inside my method Common.Encrypt?
thanks,
afiq
SIGN IN To post a reply.
5 Replies
TS
Thavasianand Sankaranarayanan
Syncfusion Team
June 24, 2019 01:40 PM UTC
Hi Muhammad,
Greetings from Syncfusion.
Query: For value that is pass using from data grid based on click details for each row, we use this kind of syntax (ex: ${DocNumber}). I can't figure out how to pass the value in my function because it makes the syntax wrong for rel='nofollow' rel='nofollow' href link. please find below my code for better understanding.
We have validated your query and we suspect that you want to change the URL dynamically when clicking anchor tag. Here, we have rendered anchor tag in one of the columns in the grid by using column template. We have dynamically changed the URL when clicking anchor tag in one of the columns of the grid. Please find the below code example and sample for your reference.
[code example]
|
<div>
@Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.dataSource).Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width("120").ValidationRules(new { required = true }).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("CustomerID").HeaderText("Customer Name").Width("150").ValidationRules(new { required = true, minLength = 3 }).Add();
col.Field("ShipName").HeaderText("Ship Name").Width("150").Add();
col.Field("ShipCountry").HeaderText("Ship Country").Width("150").EditType("dropdownedit").Add();
col.HeaderText("Row ID").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).Template("#template").Width("150").Add();
}).AllowPaging().PageSettings(page => page.PageSize(8)).EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Normal); }).Toolbar(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" }).Render()
</div>
<script id="template" type="text/x-template">
</script>
<script>
function getDetail(e, a) {
var gridIns = document.getElementById("Grid").ej2_instances[0];
var encrptData = gridIns.getRowInfo(e.target).rowData.OrderID * 2;
a.rel='nofollow' href += encrptData;
}
</script> |
If can also achieve this by using default template syntax. Please find the below documentation for your reference.
Please get back to us if you need further assistance.
Regards,
Thavasianand S.
AF
afiqdoherty
June 26, 2019 03:20 AM UTC
thank you for the reply, I have review the documentation in https://ej2.syncfusion.com/documentation/common/template-engine/?_ga=2.244129282.62597402.1561367958-1360714905.1544582736 under available template syntax. My requirement is just like Window Function/Custom helper Function but using my own function.
My function is called like this @Common.Encrypt("parametervalue", true). it is encrypt method under Common class. So, i just refer window function sample but the syntax is wrong. the parameter value is string.
this is what i am doing currently, which is wrong.
<a rel='nofollow' href='Manifest_OUT_ScoringReport?Manifest_No=${Common.Encrypt(DocNumber, true)}'><span style="font-weight: 500;"> ${DocNumber} </span></a>
hope you understand and help me the right way..
thanks
afiq
TS
Thavasianand Sankaranarayanan
Syncfusion Team
June 27, 2019 08:51 AM UTC
Hi afiq,
We have checked your query and you can achieve your requirement by using the below way. We have prepared a sample where we have called the function uppercase under available template syntax. Like that you can customize your own function. Please refer the below code example and sample link.
[Index.cshtml]
|
<div>
@Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.dataSource).Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width("120").ValidationRules(new { required = true }).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
. . . .
col.HeaderText("Row ID").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).Template("#template").Width("150").Add();
}).AllowPaging().PageSettings(page => page.PageSize(8)).EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Normal); }).Toolbar(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" }).Render()
</div>
<script id="template" type="text/x-template">
<a rel='nofollow' href="${upperCase(data.CustomerID)}">Hello</a>
</script>
<script>
function upperCase(str) {
return str.toLowerCase();
}
</script>
|
Please get back to us if you need further assistance.
Regards,
Thavasianand S.
AF
afiqdoherty
July 3, 2019 02:52 AM UTC
Hi, thanks for the reply..
i am sorry to mention that my function Common.Encrypt is actuall a method in C# class under Common class in method called Encrypt. Therefore , the value is actually passed to C# controller to encrypt the passed parameter ${DocNumber} that I currently still failed to passed to hyperlink .
below is my code in C# class to encrypt ${DocNumber} value from hyperlink when user click the grid column:
public static string Encrypt(string toEncrypt, bool useHashing = true)
{
/*
encrypt logic
*/
}
Thanks,
afiq
TS
Thavasianand Sankaranarayanan
Syncfusion Team
July 3, 2019 01:58 PM UTC
Hi Muhammad,
From your query, we found that you want to pass the value to the your controller method (i.e Encrypt) by using the anchor tag click action. So, please use the below syntax to achieve this requirement,
|
<script id="template" type="text/x-template">
</script>
|
Regards,
Thavasianand S.
SIGN IN To post a reply.
- 5 Replies
- 2 Participants
-
AF afiqdoherty
- Jun 21, 2019 08:47 AM UTC
- Jul 3, 2019 01:58 PM UTC