HTML CODE
<div data-controller="hide-modal">
<button data-action='click->hide-modal#greet'> Greet </button>
</div>
stimulus Controller
import { Controller } from "#hotwired/stimulus"
// Connects to data-controller="hide-modal"
export default class extends Controller {
greet() {
console.log('Hello')
}
}
ERROR i'm getting
Whats wrong i am doing?
Related
I need help on an implementation of a problem I have encountered. I'm currently coding a Blazor application. My index.razor component has the following code.
#page "/"
#namespace AutoHarp3_Server.Pages
#using ElectronNET.API;
#using ElectronNET.API.Entities;
#inject NavigationManager Navigation
#inject pCharStat pCharStat
<div class="FullColorBackground vh-100">
<div class="d-flex flex-column justify-content-center align-items-center vh-100">
<div class="p-4 bg-light-opactity-light border rounded-lg">
<div class="w-100">
<button class="btn btn-success btn-gradient shadow w-100" #onclick="() => CreateNewCharacter()">Create New Character</button>
</div>
<div class="mt-4 w-100">
<button class="btn btn-success btn-gradient shadow w-100" #onclick="() => OpenCharacter()">Open Character</button>
</div>
</div>
</div>
</div>
#code{
protected override void OnInitialized()
{
pCharStat.electron = new ElectronCls(new pCharacterCls());
pCharStat.electron.BuildMenu();
}
async Task CreateNewCharacter()
{
//User Clicks on button from component I am brought here to make construct a new character.
}
async Task SaveCharacter()
{
//User clicks on button from component I am brought here to save the character to a file
}
async Task OpenCharacter()
{
//User click on button from component I am brought here to open a character file.
}
}
All of this works great from the component. But in Electron there is also the menu options for each of these "NewCharacter", "SaveCharacter", and "OpenCharacter". We can see this from the ElectronCls.cs object shown below.
using AutoHarp3_Server.Data.Classes.CharacterClasses;
using AutoHarp3_Server.Pages;
using ElectronNET.API;
using ElectronNET.API.Entities;
using System;
using Microsoft.AspNetCore.Components;
namespace AutoHarp3_Server.Data.Classes
{
public class ElectronCls
{
public ElectronCls()
{
}
public string FilePath { get; set; } = "";
public void BuildMenu()
{
//Code to build menu
}
public async Task NewCharacter()
{
//Electron Menu will call this function here! How do I gain access to my index.razor component so I can move functionality to that component. I want to do this because my main character object is located there.
}
public async Task ShowOpenDialog(bool CharacterFile = true, bool ImageFile = false)
{
//electron Menu will call this function here! How do I gain access to my index.razor component so I can move functionality to that component. I want to do this because my main character object is located there.
}
public async Task ShowSaveDialog()
{
//electron Menu will call this function here! How do I gain access to my index.razor component so I can move functionality to that component. I want to do this because my main character object is located there.
}
}
}
If the user uses the electron menu I do not see any way from going to the methods I have defined in my ElectronCls.cs object to the index.razor component. I do not see any way to call it. I'm not sure this is possible or if this is the way one should do it in Blazor. The reason I need to find a solution is that since this is an Electron application, the user could use the menu. I should have that option open to them. If there is no way to accomplish this, I suppose I can look into removing the menu altogether from the application.
EDIT: for clarification purposes as requested.
Ok so I am fairly new at AngularJS and just running through a demo, but I am having issues with the routing side of things and can't figure it out. I thought you guys would know instantly that I have done something dumb.
So here goes.
This is my JS file
var WebApplication2 = angular.module('WebApplication2', ['ng-route']);
WebApplication2.controller('LandingPageController', LandingPageController);
WebApplication2.config([
'$routeProvider',
function ($routeProvider) {
$routeProvider
.when('/routeOne', {
templateUrl: 'routesDemo/one'
})
.when('/routeTwo', {
templateUrl: 'routesDemo/two'
})
.when('/routeThree', {
templateUrl: 'routesDemo/three'
});
}
]);
And here is my html code
<html ng-app="WebApplication2" ng-controller="LandingPageController">
<head>
<title ng-bind="models.helloAngular"></title>
</head>
<body>
<h1>{{models.helloAngular}}</h1>
<ul>
<li>Route One</li>
<li>Route Two</li>
<li>Route Three</li>
</ul>
<div ng-view></div>
<script src="~/Scripts/angular.min.js"></script>
<script src="~/Scripts/angular-route.min.js"></script>
#Scripts.Render("~/bundles/AngularBundle")
</body>
</html>
I also have this js controller file
var LandingPageController = function ($scope) {
$scope.models = {
helloAngular: 'I work!'
};
}
I then have a controller with the following actionresults
public class RoutesDemoController : Controller
{
public ActionResult One()
{
return View();
}
public ActionResult Two()
{
return View();
}
public ActionResult Three()
{
return View();
}
}
This is a dependency injection error.
Try this :
var WebApplication2 = angular.module('WebApplication2', ['ngRoute']);
instead of :
var WebApplication2 = angular.module('WebApplication2', ['ng-route']);
Since you are using routing, you should not declare an ng-controller attribute on your view. With routing, each of your views can use a different controller.
Instead of the HTML tag you mentioned above, it should be like this:
<html ng-app="WebApplication2">
You should declare the controller you wish to use in your route. The templateUrl is the path to the HTML file you will use as the template:
$routeProvider.when('/routeOne', {
templateUrl: 'views/route-one.html',
controller: 'LandingPageController'
})
Your controller's code should look something like this:
WebApplication2.controller('LandingPageController', function ($scope) {
$scope.models = {
helloAngular: 'I work!'
};
});
Where you are using <h1>{{models.helloAngular}}</h1> that is not in the scope of your route. The views for your routes will render in <div ng-view></div>.
In your views/route-one.html file you can add <h1>{{models.helloAngular}}</h1>.
You can view this page in the docs for an example implementation of ngRoute.
Angular is used to build single-page applications—your ASP.net's router will have nothing to do with Angular's routes. You just need to declare a single static route that is pointed to your Angular application. Server-side and client-side routing will not work hand-in-hand.
I am manually adding the following Model Error in my controller,
ModelState.AddModelError(string.Empty, "An error occurred");
However when the view is loaded, the #Html.ValidationSummary(true) is not showing any errors.
I have also tried #Html.ValidationSummary(false).
I have read many articles on this behavior and I have tried all the suggestions with no luck.
Any suggestions are greatly appreciated!
I can see it work. See the sample here: http://dotnetfiddle.net/Jz7wQj
Beware when using custom ViewData objects.
Problem Reproduced
Model
using System.ComponentModel.DataAnnotations;
namespace BrokenValidationSummaryTest.Models
{
public class MyModel
{
[Required]
public string Whatever { get; set; }
}
}
Controller
using BrokenValidationSummaryTest.Models;
using System.Web.Mvc;
namespace BrokenValidationSummaryTest.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Submit(MyModel postedData)
{
return View(viewName: "Index", model: postedData);
}
}
}
View "Index"
#model BrokenValidationSummaryTest.Models.MyModel
<ul class="nav nav-tabs" id="carrier-tabs">
<li class="active">
<a data-toggle="tab" href="#search" class="tab-level-1" data-tab-name="search">Search</a>
</li>
</ul>
<div class="tab-content">
<div id="search" class="tab-pane fade in active">
#Html.Partial(partialViewName: "TabBody", model: Model, viewData: new ViewDataDictionary())
</div>
</div>
View "TabBody"
#model BrokenValidationSummaryTest.Models.MyModel
#Html.ValidationSummary(excludePropertyErrors: false)
<h2>TabBody</h2>
#using (Html.BeginForm(actionName: "Submit", controllerName: "Home", method: FormMethod.Post))
{
<div>Whatever:</div>
<div>#Html.TextBoxFor(x=>x.Whatever)</div>
<input type="submit" value="Submit">
}
Explanation
The partial view has the ValidationSummary HTML helper. We pass a custom ViewData object to the partial view. This custom ViewData object passed to the partial view does not contain the ViewState found in the view 'Index'. The HTML helper ValidationSummary does not have enough required information to render the error messages properly.
Recommendation: if using custom ViewData, populate the custom ViewData with the ViewState of the parent view.
I'm can't find any doc that explains how to manipulates forms in Angular Dart.
I've got the following code in my_component.html:
<form name="form" ng-submit="comp.save()">
<input type="text" required ng-model="comp.user.firstname">
<input type="text" required ng-model="comp.user.lastname">
<button ng-disabled="form.invalid">Save</button>
</form>
And the following one in my_component.dart:
#NgComponent(
selector : 'my-component',
templateUrl : 'my_component.html',
publishAs : 'comp'
)
class MyComponent {
#NgTwoWay('user')
User user;
#NgTwoWay('form')
NgForm form;
MyComponent() {};
void save() {
print(form);
}
}
The validation works well, but when clicking on the button, the print(form) statement always prints null.
Any idea?
Thanks
I guess this is what you want:
class MyComponent {
#NgTwoWay('user')
User user = new User();
Scope scope;
MyComponent(this.scope) {}
void save() {
var form = (scope.context['form'] as NgForm);
print(form.invalid);
}
}
In our application we are using Tabs to display the information for example contacts, in this tab the user can switch between view contacts and created contact. When the user clicks on ‘Create’ I want the partial view changed to CreateContact within the same tab. What is the best way to show hide a Partial Views in jquery UI tabs? Should I use Ajax code to do this?
View
<div id="tabs">
<ul>
<li>Claim</li>
<li>Products</li>
<li>Contact Us</li>
</ul>
</div>
Controller
public ActionResult GetContact()
{
return PartialView();
}
public ActionResult CreateContact()
{
return PartialView();
}
Partial View
<li>#Html.ActionLink("Create", "Test", "Home")</li>
Thanks
Yes, you can use AJAX. That is in case you don't want to load all partial views at once.
If it doesn't matter, you can just render them at once:
<div id="tabs-1">
#Html.Partial("GetClaim")
</div>
<div id="tabs-2">
#Html.Partial("GetProduct")
</div>
<div id="tabs-3">
#Html.Partial("GetClaim")
</div>
jQuery hides the elements that are not currently visible and will manage the switching automatically.
You can use an Ajax.ActionLink() - http://msdn.microsoft.com/en-us/library/dd493106.aspx
This will asynchronously submit your form to your controller method. If you set the AjaxOptions.InsertionMode to be AjaxOptions.InsertionMode.Replace then it will replace the partial view content with whatever you return from the controller. Then, you just need to return the GetContacts view in the creatcontacts controller action, as below:
[HttpGet]
public ActionResult GetContact()
{
return PartialView(RetrieveListOfContacts());
}
[HttpPost]
public ActionResult CreateContact(StronglyTypedContactModel contact)
{
if (ModelState.IsValid)
{
// .. write your contact here
return PartialView("GetContact", RetrieveListOfContacts());
}
else
{
return PartialView(contact);
}
}
EDIT
Also, you can specify that it be a GET request in the HttpMethod of the AjaxOptions, so as not to require form (as I originally assumed you did).