I recently upgraded from MVC 4 to MVC 5. Since that upgrade, my Code Snippets have not been working that I previously created. There are almost no resources online for this (for MVC 5) and any previously tutorial that shows how to create a snippet does not work. I'm using Visual Studio 2013 (update 1, but update 2 also does not fix it).
Here's my snippet:
<CodeSnippet Format="1.1.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<Header>
<Title>JSLessBehavior</Title>
<Author>OptixConnect LLC</Author>
<Shortcut>jslessBehavior</Shortcut>
<Description>Markup snippet for a JSLess behavior helper</Description>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>name</ID>
<ToolTip>name</ToolTip>
<Default>execute</Default>
</Literal>
<Literal>
<ID>toggle</ID>
<ToolTip>toggle</ToolTip>
<Default>toggle</Default>
</Literal>
<Literal>
<ID>target</ID>
<ToolTip>target</ToolTip>
<Default>self</Default>
</Literal>
<Literal>
<ID>params</ID>
<ToolTip>params</ToolTip>
<Default>params</Default>
</Literal>
</Declarations>
<Code Language="html">
<![CDATA[data-jsless="#(new object[] { new { name = "$name$", method = "$toggle$", target = "$target$", #params = new object[] { "$params$" } } }.ToJsonObject())"]]>
</Code>
</Snippet>
The expected outcome would be if I start typing <div jslessBehavior and then press tab + tab it should auto generate that snippet. Has something changed when going from MVC 4 to 5?
The default code snippets that Visual Studio provides work. And I tried copying one of their HTML snippets and just refactoring it to use my code with no luck :(
Related
I am trying to integrate blazor server into an existing MVC project, and am a little confused as to the requirements for getting my components to call OnAfterRenderAsync().
I have the following simple Index.razor page for testing made up of the following:
#page "/Index"
<h1>Counter</h1>
<p>Current count: #currentCount</p>
<button class="btn btn-primary" #onclick="IncrementCount">Click me</button>
#code {
private int currentCount = 0;
protected override Task OnAfterRenderAsync(bool firstRender)
{
return base.OnAfterRenderAsync(firstRender);
}
private void IncrementCount()
{
currentCount++;
}
}
If I navigate directly to /Index the OnAfterRenderAsync method is hit just fine. But if I render Index.razor as a component in my cshtml like this:
#(await Html.RenderComponentAsync<Index>(RenderMode.ServerPrerendered ))
Then the OnAfterRenderAsync() is not hit.
I have MapBlazorHub() in my Startup.cs and <script src="~/_framework/blazor.server.js"></script> in my _Host.cshtml.
Have I missed a step somewhere or is this behavior by design in Blazor Server, and if so, is there some workaround?
I need some reusable blazor components to be able to work with JS libraries that were implemented in the MVC project, so I need those components to be able to call OnAfterRenderAsync() without going directly to the page URL
After inspecting the sources in developer tools I saw that the folder for _framework was not present in my component.
Even though I could navigate to https://myurl/_framework/blazor.server.js and saw the file was present in my project, my component didn't have access to it. adding the script tag <script src="~/_framework/blazor.server.js"></script> directly to my cshtml file that was rendering my Blazor component fixed my issue.
I'm planning to develop an web application wherein there's an WYSIWYG text editor which you can save to database and export the output into DOCX/MS WORD. I could only find word automation/export on c#, but I need the text editor to be real time so that number of clients can edit at the same time.
I'm thinking of using asp.net core with angular typescript and ms sql to build this app. And unfortunately I'm struggling on how I can generate the Word Document on c# when the page is rendered in Angular Typescript.
using Word = Microsoft.Office.Interop.Word;
using System.Reflection;
private void Generate()
{
object oMissing = System.Reflection.Missing.Value;
object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
//Start Word and create a new document.
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,
ref oMissing, ref oMissing);}
//so on and so forth
home.component.html
<button type="button" class="btn btn-primary btn-md" (click)="Generate()">
Show Message
</button>
I'm new to angular, but if there's a better a approach rather than asp.net core and angular typescript or different language / library I could use feel free to comment.
Also if I can get this working I would be much easier for me.
This has been driving me crazy for about 3 hours now. We upgraded from Umbraco 4 to Umbraco 7 and now our site menus are broken. We used to use a script that traversed the nodes and created a CSS menu system.
So I have started reading up on the new stuff and I just can't even get a #helper or #functions block to work. The script is now using a PartialView Macro that uses a parameter called MenuNode that is the Node I want to traverse down.
Here's the code that works:
#inherits Umbraco.Web.Macros.PartialViewMacroPage
#{
var menuNode1 = string.IsNullOrEmpty((string)Model.MacroParameters["MenuNode"])? 0 : Convert.ToInt32(Model.MacroParameters["MenuNode"]);
}
<h1>#menuNode1</h1>
As soon as I try to add a #helper or #functions like in the Navigation PartialView example provided in Umbraco it stops working. Here is what breaks it.
#inherits Umbraco.Web.Macros.PartialViewMacroPage
#{
var menuNode1 = string.IsNullOrEmpty((string)Model.MacroParameters["MenuNode"])? 0 : Convert.ToInt32(Model.MacroParameters["MenuNode"]);
}
#TestHelper(menuNode1)
#helper TestHelper(var testvalue)
{
<h1>#testvalue</h1>
}
Can anyone point me at what I'm doing wrong?
Problem solved. It was because I was using var in the #helper parameter list, changed to dynamic and it worked fine.
I'm working on a website which has the following code in an ascx page:
<%Using (Html.BeginForm("MakeABooking", "User", FormMethod.Post))%>
<button type="submit" class="searchCarButton JQryStyleButton" name="btnSubmit" value="1; <%:DataBinder.Eval(c.DataItem, "currentAsset.AssetID").ToString %>; <%:DataBinder.Eval(c.DataItem, "SearchForDate").ToString %>">Make Booking</button>
<%End Using%>
This form calls the MakeABooking Function in a ViewController:
<HttpPost()> _
<ValidateInput(False)> _
Public Function MakeABooking(btnSubmit As String) As ActionResult
Dim sMan As String = btnSubmit
Dim sSegmentBooked As String = sMan.Substring(0, sMan.IndexOf(";"))
sMan = sMan.Substring(sMan.IndexOf(";") + 1)
Dim sAsseID As String = sMan.Substring(0, sMan.IndexOf(";"))
Dim sDateBook As String = sMan.Substring(sMan.IndexOf(";") + 1)
Dim BookingModel As New BookingViewModel(CInt(sAsseID), CInt(sSegmentBooked), CDate(sDateBook))
Return View("MakeABooking", BookingModel)
End Function
When using Internet Explorer 8 with Compatibility View turned on, I get the following error Length cannot be less than zero. Parameter name: length.
However, when Compatibility View is turned off, it works fine but this causes another issue on the website I'm working on where ui-selector controls are not working properly (jQuery control).
The client whom we have created this website for is using Windows XP and Internet Explorer 8, hence needing to fix problem for Internet Explorer 8, as they are not willing to use another browser like Google Chrome or Firefox in which our website works fine on.
I've managed to replicate the problem using Windows 7 IE 9 with Compatibility mode on, and the string value passed in to the MakeABooking Function i.e. btnSubmit, is "<SPAN class=ui-button-text>Make Booking</SPAN>" whereas the string passed should be something like this "1;8463;12/09/2012 12:00:00 AM", as the Function MakeABooking is looking for semi-colons, hence that error I'm getting. Does anyone know why I get the string "<SPAN class=ui-button-text>Make Booking</SPAN>" instead of what I expect as mentioned earlier?
If I can get any assistance, it will be much appreciated.
Thanks hagensoft, adding in the following extra code to the right aspx page fixed the problem.
<asp:Content ID="Meta" ContentPlaceHolderID="MetaContent" runat="server">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
</asp:Content>
I also needed to add the following line of code in the Site.Master page in the tag.
<asp:ContentPlaceHolder ID="MetaContent" runat="server" />
Well, I think the ASP.NET MVC team released a pretty significant bug in the developer preview for asp.net mvc 4, or I'm doing something stupid... Here's the issue and steps to reproduce.
Create a new MVC 4 mobile application
create a new section in the layout (ex. #RenderSection("head",false))
in the controller action just throw a Message into the ViewBag
then in a view that uses the main layout, add the following code below.
#section head {
$(function() {
var newVariableName = "#(ViewBag.Message)";
});
}
You'll notice that the razor parser actually thinks that the section has been completed for the jquery on dom loaded ending brace instead of the section's ending brace. I tried the exact same code in an asp.net MVC 3 application and it worked with no issues.
Has anyone else come across this bug in the ASP.NET MVC 4 Developer Preview?
A quick hack to solving this issue is to use < text > blocks < /text > around the java script. Here's what it might look like until the ASP.NET MVC team resolves this bug.
#{
<text>
$(function()
{
var newVariableName = "#(ViewBag.Message)";
});
</text>
}
As mentioned above, try this in your cshtml file...
#section head {
#{
function JSMeth1()
{
// doing your stuff, razor parser wont suck
}
}}