ActionLink MVC4 Razor with icon class - asp.net-mvc

I have this code HTML:
<a class="tooltip-tip2 ajax-load" href="...."><i class="entypo-menu"></i><span>Page Example</span></a>
And I would use this:
#Html.ActionLink("Crea mensilizzazione " + s.nome, "CheckCredentials", "giornaliero", new { #class= "tooltip-tip2 ajax-load" , id=s.id, isScuole = false},null)
How can add the <i class="entypo-menu"></i> in this #HTML.ActionLink???

I don't think the ActionLink helper can accomplish this. but you can use #Url.Action() in custom markup to accomplish the same thing:
<a class="tooltip-tip2 ajax-load" href="#Url.Action("CheckCredentials", "giornaliero")"><i class="entypo-menu"></i><span>Page Example</span></a>
Url.Action basically just creates the URL for the link, not any of the markup related to building the link itself. So it can be used in all sorts of custom client-side code. (For example, another common use is to embed it in some JavaScript code to define an AJAX service URL.)
Edit: You can add route values exactly the same way as you do with #Html.ActionLink:
#Url.Action("CheckCredentials", "giornaliero", new { id = s.id, isScuole = false })

Related

Umbraco 6.2.0 Render maco inside a razor macroscript

I have the below code which works but is there a better way using the RenderMacroContent method. Not sure how to add parameters to that.
<umbraco:Macro runat="server" language="cshtml">#{
HtmlTextWriter writer = new HtmlTextWriter(this.Output);
var macroPressLogin = new umbraco.presentation.templateControls.Macro();
macroPressLogin.Alias = "Security-PressLogin";
macroPressLogin.Attributes.Add("TargetNode", Parameter.TargetNode);
macroPressLogin.RenderControl(writer); }</umbraco:Macro>
As long as your view inherits from Umbraco.Web.Mvc.UmbracoTemplatePage or Umbraco.Web.Mvc.UmbracoViewPage<YourModel> you should just be able to write something like:
#Umbraco.RenderMacro("MacroAlias", new { ParameterAlias1 = "value1", ParameterAlias2 = "value2" })
So in your case it would be:
#Umbraco.RenderMacro("Security-PressLogin", new { TargetNode = "targetNodeValue" })
If you're talking about calling one macro from within another then this should also work as long as your macro partial view inherits from Umbraco.Web.Macros.PartialViewMacroPage
From your example it looks like you're working with a legacy razor macro using umbraco.MacroEngines. If possible I would recommend upgrading to a partial view macro. Click here for some further info.
I know this question is a year old, but I hope someone finds a use for this information (using Umbraco version 6.x):
#(Html.Raw(umbraco.library.RenderMacroContent("<?UMBRACO_MACRO macroAlias=\"MacroAliasHere\" dynamicParameter=\""+ #dynamicValue + "\" staticParameter=\"staticValue\" ></?UMBRACO_MACRO>", Model.Id)))
Option number 2, which I prefer, is actually code to output a contour form using a value from the form picker datatype:
var helper = new UmbracoHelper(UmbracoContext.Current);
#Html.Raw(helper.RenderMacro("umbracoContour.RazorRenderForm", new { formGuid = #Model.formPickerAlias }))

asp.net-mvc routing does not route with this anchor element

For asp.net-mvc routing, my link is this:
<a href='product/product_description/#:product_id#' >
but it is passing as this:
http://localhost:58166/product/product/product_description/1102
I expected it to be:
http://localhost:58166/product/product_description/1102
What am I doing wrong?
You need to perpend forward slash
<a href='/product/product_description/#:product_id#' >
However you would be much better off using a helper rather than hard coding
#Html.ActionLink("Link text", "product_description", "product" { new ID = ?? })

Thickbox in asp.net mvc

I want to use Thickbox in my site.
I have the following code:
<img src='#Url.Action("GetSchemaImage", "Hall", new {folderName = #Model.FolderName })'/>
This is generated markup:
<a class="thickbox" href="/Hall/GetSchemaImage?folderName=marineclub"><img src="/Hall/GetSchemaImage?folderName=marineclub"></a>
The image shows correctly, but when I click on it, it opens in the current window.
How to resolve it?
Thanks
try another signature for the HTML ActionLink helper and see if this works
#Html.ActionLink("GetSchemaImage", "Hall",new {folderName = #Model.FolderName },new{})

DevExpress DateEdit using MVC

I have just started using the
<% Html.DevExpress().DateEdit()
control and i got it to work fine in my ASP.Net MVC application. The code is as shown below:
aspx page:
<% Html.DevExpress().DateEdit(settings =>
{
settings.Name = "EndDate";
settings.Properties.NullText = "dd/MM/yyyy";
settings.Properties.EditFormat = EditFormat.Custom;
settings.Properties.EditFormatString = "dd/MM/yyyy";
settings.Properties.DisplayFormatString = "dd/MM/yyyy";
settings.Date = Model.EndDate;
settings.Width = 100;
}
).Render();
%>
Above this code i have a reference to my javascript file (DateChanges.js) in this file i want to be able to do something like:
$(document).ready(function(){
$("#EndDate").change(function(){
//do whatever i want
});
})
I cant do this now cause using firefox i can see that the actual textbox that this datepicker assigns a value to has be named "EndDate_I". So my question is how can i easily do this since i want to be able to catch the change event of this control and play around with it in jQuery??
The DevExpress MVC Extensions offer their own infrastructure for the client-side processing needs (see the http://help.devexpress.com/#AspNet/CustomDocument6908 help topic to getting started).
It is necessary to handle the client-side ASPxClientDateEdit.DateChanged event, and retrieve the newly selected Date via the client-side ASPxClientDateEdit.GetDate() method. Use the retrieved js Date object for your additional needs:
<script type="text/javascript">
function OnDateChanged(s, e) {
var newDate = s.GetDate();
alert(newDate);
}
</script>
settings.Properties.ClientSideEvents.DateChanged = "OnDateChanged";
There is a rather long Blog post at http://kennytordeur.blogspot.com/2011/05/aspnet-mvc-where-is-clientid_10.html discussing your problem
( I think it is to long to have it pasted here, and the author deserves the credits )
following on from your comment on Mikhails's answer, there will be a property in the global namespace with the name of your control, so it's just like this:
CalculateDayDifference(s.GetDate(), EndDate.GetDate());
All the mvc controls do this, for some you might have to set the EnableClientSideApi property to start using them.

Using Html.ActionLink() with ASP.NET MVC & Spark - Syntax?

All,
Doing some experimenting with Spark and MVC within NerdDinner. The normal/aspx view works well, and I haven't touched any of the controller code so I'm pretty sure it's not that.
<viewdata model="System.Collections.Generic.IEnumerable[[NerdDinner.Models.Dinner]]"/>
<set Title="'Upcoming Dinners'"/>
<content:main>
<li each="p in Model">
!{Html.ActionLink(p.Title, 'Details', 'Dinners')}
</li>
</content:main>
Given the code above, the ActionLink gets rendered as http://serverName/Controller/Action/
Which is good. I start hitting a wall when I try to provide the ID to my action method. As far as I can tell from the Spark sample docs, I should be able to do something like this:
!{Html.ActionLink(p.Title, 'Details', 'Dinners', new {id = p.DinnerID} )}
However, that throws an exception:
" unexpected token '{' "
I'm hoping it's something silly I'm missing...any suggestions?
I believe there should be another parameter to Html.ActionLink for HTML attributes on the action link. Try:
!{Html.ActionLink(p.Title, 'Details', 'Dinners', new {id = p.DinnerID}, null )}

Resources