display a comment on action links - asp.net

How to display a comment when the user mouse is over an action link? I'm using a gridview and here is one of my columns that contains an action link :
grid.Column(header: "", format: (item) => Html.ActionLink("Détails", "Details",
new { id = item.id_projet}, new { #class = "details" }), style: "actions")

Do you mean a title?
grid.Column(header: "", format: (item) => Html.ActionLink("Détails", "Details",
new { id = item.id_projet}, new { #class = "details", #title = "text here" }),
style: "actions")
This will display the text text here if you hover the link.

Related

Display form in bootstrap modal on button click using Datatables

Having a JQuery Datatable (it's more complex I simplified it) as below:
I need to display a bootstrap modal form with a text input field on, whenever I click the "Assign Card" button.
The modal should should be populated with the data coming from the row in which the button was clicked.
Upon clicking the modal "Assign" button, normally I should post the inputed value and the "VisitorID" which like "John Doe" should come from the specific row.
On Assign I should post the "input value" and "VisitorID".
What I have so far:
var table = $('#visitorsTable').DataTable({
"ajax": {
...
},
"columns": [
{ "data": "VisitorID" },
{ "data": "FirstName" },
{ "data": "LastName" },
{
"data": "CheckedIn",
"render": function(d) {
return moment(d).format('DD-MM-YYYY HH:mm');
}
},
{"data": "CardNumber"},
],
columnDefs: [
{
targets: [0], // Visitor ID
visible: false
},
{
targets: [-1],
render: function(cardNUmber, b, data, d) {
return '<button class="btnAssignCard data-toggle="modal" data-target="#assignCardModal" float-right">Assign Card</button>';
}
}
]
});
$('#visitorsTable').on('click',
'.btnAssignCard',
event => {
// THIS IS HOW I GET ACCESS TO THE SPECIFIC ROW
let rowData = table.row($(event.target).parents('tr')).data();
var visitorID = rowData.VisitorID;
var visitorFirstName = rowData.FirstName;
var visitorLastName = rowData.LastName;
});
});
Remove the data-toggle and data-target from the button.
Then call the below function after
// THIS IS HOW I GET ACCESS TO THE SPECIFIC ROW
let rowData = table.row($(event.target).parents('tr')).data();
var visitorID = rowData.VisitorID;
var visitorFirstName = rowData.FirstName;
var visitorLastName = rowData.LastName;
showMyModalSetInput(visitorFirstName + visitorLastName,visitorID );
The function will open the modal and pass the required values before opening. Also, for visitor id, you can add an extra hidden input.
function showMyModalSetInput(inputText, visitorID) {
$('#inputId').val(inputText);
$('#hiddenInputforVisitorID').val(visitorID);
$('#assignCardModal').modal('show');
}

How to set the selected value of an MVC5 DropDownList?

Given the following MVC5 code:
#Html.DropDownList(name: "Enhanced_Rijndael_AlgorithmID", optionLabel: null, selectList: EnhancedRijndaelAvailableHashAlgorithmList.Select(item => new SelectListItem
{
Value = item.RecordID.ToString(),
Text = item.HashAlgorithm,
Selected = "select" == item.RecordID.ToString()
}), htmlAttributes: new { #class = "form-control" })
Is it possible to set the "selected value" of this list?
The only thing I can think of is somehow setting the Selected value in the SelectListItem set.
Here is the what Ive come up with after being reminded of the DropDownListFor
#Html.DropDownListFor(expression: r => r.AlgorithmID, selectList: EnhancedRijndaelAvailableHashAlgorithmList.Select(item => new SelectListItem
{
Value = item.RecordID.ToString(),
Text = item.HashAlgorithm,
Selected = "select" == item.RecordID.ToString()
}),
htmlAttributes: new { #class = "form-control" }, optionLabel: "Algorithm")

Html.SelectFor razor syntax add class

I want to add a class to a selectfor
but I get an error
#Html.SelectFor(m => m.foo, optionLabel: null, new { #class = "foo12" })
With a text box it works:
#Html.TextBoxFormattedFor(m => m.foo, new { #class = "foo" })
Error I get:
Named argument specifications must appear after all fixed arguments have been specified.
The error is self-explanatory -- any named arguments (in this case "optionLabel") have to come after unnamed ones. So instead of this:
#Html.SelectFor(m => m.foo, // 1
optionLabel: null, // 2
new { #class = "foo12" } // 3
)
I guess you probably want this:
#Html.SelectFor(m => m.foo, // 1
optionLabel: null, // 2
htmlAttributes: new { #class = "foo12" } // 3
)
Edit
Surely you mean DropDownListFor, and not "SelectListFor"? You need to provide the options as well. Something like this:
#{
var selectList = new SelectListItem[]
{
new SelectListItem { Text = "text", Value = "value" },
};
}
#Html.DropDownListFor(m => m.foo,
selectlist: selectlist,
htmlAttributes: new { #class = "foo" }
)

webgrid sort not working

I'm using webgrid to show data from my data base. The problem is that sort option is not working
Here is my webgrid code
#{
var grid = new WebGrid(Model, canPage:true ,canSort:true, rowsPerPage :4);
grid.Pager(WebGridPagerModes.NextPrevious);
#grid.GetHtml(tableStyle: "webGrid", htmlAttributes: new { id = "datatable" },
headerStyle: "webgrid-header",
selectedRowStyle : "webgrid-selected-row",
footerStyle : "webgrid-footer",
rowStyle: "webgrid-row-style",
alternatingRowStyle: "webgrid-alternating-row",
columns: grid.Columns(
grid.Column(header: "", format: (item) =>
Html.ActionLink("Détails", "Details", new { id = item.id_client }, new { #class = "details" }), style: "actions"),
grid.Column(header: "", format: (item) => Html.ActionLink("Modifier", "Edit", new { id = item.id_client }, new { #class = "modifier" }),style : "actions"),
grid.Column(header: "", format: (item) => Html.ActionLink("Supprimer", "Delete", new { id = item.id_client }, new { #class = "supprimer" }), style: "actions"),
grid.Column("Nom",canSort: true),
grid.Column("Prenom", "Prénom",canSort:true),
grid.Column("Email")));
}
You can try add the list of name columns for your webgrid, for example:
var grid = new WebGrid(canPage:true ,canSort:true, rowsPerPage :4);
grid.Bind(Model,columnNames: new[] { "Nom", "Prenom"}); //adding names of columns
grid.Pager(WebGridPagerModes.NextPrevious);
#grid.GetHtml(...
Sometimes web grid can't understand how bind your model with columns.
Yes, James's answer worked for me. The sort links were working for some of the columns and not others, adding the columnNames: made it work properly.
Steve

MVC Telerik Grid Conditional column Value?

How can i get this work in MVC Telerik Grid Control
columns.Template(e =>
{
if (e.EndDate>DateTime.Now )
{
#Html.ActionLink("Stop", "StopMedication", "Medication",
new { id = e.PrescriptionID }, new { #class = "standard button" })
}
else {
#Html.ActionLink("Renew", "RenewMedication", "Medication",
new { id = e.PrescriptionID }, new { #class = "standard button" })
}
});
The following snippet should work perfectly fine in the Telerik Grid template column using Razor syntax:
columns.Template(
#<text>
#if (#item.EndDate > DateTime.Now)
{
#Html.ActionLink("Stop", "StopMedication", "Medication",
new { id = #item.PrescriptionID }, new { #class = "standard button" })
}
else
{
#Html.ActionLink("Renew", "RenewMedication", "Medication",
new { id = #item.PrescriptionID }, new { #class = "standard button" })
}
</text>
);
Taking use of the #<text></text> inside of the template, as well as using the #item object, which represents the current item (entity tied to the row) and it's properties, will allow you to have this template up and running.

Resources