I have a list of users and if you click on a user there has to be create a new message.
But every time I click on a user id is 0
I have this:
action method:
public ActionResult StuurBericht(int id = 0, string onderwerp = "")
{
using (var rep = new GebruikerRepository(Context.Klant.Id))
{
var model = PersoneelsDossierService.GetPersoneelsDossierMutatieModel(Context.Klant.Id, GetMutatieRol(), int.Parse(Context.Gebruiker.ExternId), Gebruiker.DienstverbandId, Gebruiker.DienstverbandId, "Functionarissen");
model.Functionarissen = PersoneelsDossierService.GetFunctionarissen(Context.Klant.Id, Gebruiker.DienstverbandId);
BeveiligingService.ControleerGebruikerVanKlant(Context.Klant.Id, Context.Gebruiker.Id);
if (id > 0)
{
ModelState.Clear();
var modelMessage = new Message();
modelMessage.GebruikerId = id;
modelMessage.Onderwerp = string.Format("RE: {0}", onderwerp);
return View(model);
}
}
return View();
}
and this is the view:
#model List<SDB.Models.Stamtabel>
#{
var ItemsByAccordatieFunctieGroep = Model.GroupBy(a => a.Code);
<div class="row">
#foreach (var Accordeerders in ItemsByAccordatieFunctieGroep)
{
<div class="col-md-4">
<div class="panel panel-default">
<!-- Default panel contents -->
<div class="panel-heading blue">#Accordeerders.Key</div>
<!-- List group -->
<ul class="list-group">
#foreach (var Accordeerder in Accordeerders)
{
<li class="list-group-item">
#Accordeerder.Omschrijving
</li>
}
</ul>
</div>
</div>
}
</div>
}
So my question is:
How to return the correct user and that you will get the correct id?
Thank you
this has to be the link for new message:
SelfService/Profiel/Nieuw?id=6240&onderwerp=test
So the controller is: Profiel.
But now the link is this:
/PersoneelsDossier/StuurBericht/0?onderwerp=HRM%20Management
So the controller link is incorrect.
Your #Url.Action is wrong, it should be:
#Accordeerder.Omschrijving
Related
I have created a simple list in a razor component.it is a simple HTML list with foreach loop.
<ul>
#foreach (var itm in matchingLocations)
{
<li>
<div class="d-flex">
<div class="py-2 pr-2">
<i class="fas fa-map-marker-alt text-glow-1"></i>
</div>
<div class="py-2"><span class="sub-title-2">#itm.CodeName</span></div>
</div>
</li>
}
</ul>
Now I have needed to add the following 2 features to the list
when click on one list item, it should be highlighted.
if we want to click on another item,while one item is already highlighted, the currently highlighted item should be unhighlighted
and clicked item should be highlighted.
. how can I do this using blazor? anybody who knows about this, please help me.
There are many ways to do this. Here's a demo page showing one:
#page "/"
#foreach (var item in Countries)
{
<div class="#DivCss(item) p-2" #onclick="() => SetSelect(item)">
#item.Name
</div>
}
#code {
List<Country> Countries = new List<Country>
{
new Country { Name = "Australia"},
new Country { Name = "Spain"},
new Country { Name = "Croatia"}
};
List<Country> SelectedCountries = new List<Country>();
class Country
{
public string Name { get; set; }
}
bool IsSelected(Country country)
=> SelectedCountries.Any(item => item == country);
string DivCss(Country country)
=> IsSelected(country) ? "bg-success text-white" : "bg-light";
void SetSelect(Country country)
{
if (IsSelected(country))
SelectedCountries.Remove(country);
else
SelectedCountries.Add(country);
}
}
I am trying to pass the value from my HTML select to a controller, but I am not sure why the method is not capturing the values in spite of the select id has the same name than model.
[Authorize]
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "CountryId,ProvinceId,CityId")] ads_post ads_post)
{
var currUser = currentUser.GetCurrUser();
ads_post.UserId = currUser.Id;
ads_post.PostDate = DateTime.Now;
ads_post.SponsoredType = null;
ads_post.PriorityType = null;
if (ModelState.IsValid)
{
db.ads_post.Add(ads_post);
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.PriorityType = new SelectList(db.ads_priority_plan, "Id", "Name");
ViewBag.SponsoredType = new SelectList(db.ads_sponsored_plan, "Id", "Name");
ViewBag.CurrencyType = new SelectList(db.ads_currency, "Id", "Name");
return View(ads_post);
}
This is the HTML
<div class="row mb-3 mt-5">
<div class="col-md-4">
<label><strong>PaĆs donde quieres publicar:</strong> <i class="fas fa-list-ul"></i></label>
<select id="CountryId" onchange="getProvices();"></select>
</div>
<div class="col-md-4">
<label><strong>Provincia:</strong> <i class="fas fa-list-ul"></i></label>
<select id="ProvinceId" onchange="getCities();"></select>
</div>
<div class="col-md-4">
<label><strong>Ciudad:</strong> <i class="fas fa-list-ul"></i></label>
<select id="CityId"></select>
</div>
</div>
Can somebody help me out with this?
Thank in advance.
I found by myself, I had just to add a name attribute to the HTML and that's it.
I have a login page and registration page all are working fine. I have a users table i created in sql server database with the column Username, FullName, School, Course. I want to display all the user detail in a sidemenu view page in MVC. But when i login i get the error message"object-reference-not-set-to-an-instance-of-an-object". I also have a controller action. Please someone help.
This is for MVC
#model ORMOnlineExamApp.Models.Candidate
<div class="row">
<div class="col-md-3">
<div class="container-fluid">
<div class="thumbnail" style="width:200px">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Candidate's Details</h3>
</div>
</div>
<p>
<h4 style="font-weight:bold">Application No:</h4>
</p>
<p>
#Model.Username
</p>
<hr />
<p>
<h4 style="font-weight:bold">Name:</h4>
</p>
<p>
#Model.FullName
</p>
<hr />
<p>
<h4 style="font-weight:bold">School:</h4>
</p>
<p>
#Model.School
</p>
<hr />
<p>
<h4 style="font-weight:bold">Course:</h4>
</p>
<p>
#Model.Course
</p>
</div>
//Controller
public ActionResult Contact(string id)
{
using (ORMOnlineExamEntitiesApp db = new ORMOnlineExamEntitiesApp())
{
var user = db.Candidates.SingleOrDefault(u => u.Username == id);
return View(user);
}
}
Please find the login page below:
//Login POST
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Login(CandidateLogin login, string ReturnUrl = "")
{
string message = "";
using (ORMOnlineExamEntitiesApp dc = new ORMOnlineExamEntitiesApp())
{
var v = dc.Candidates.Where(a => a.Username == login.Username).FirstOrDefault();
if (v != null)
{
if (string.Compare(Crypto.Hash(login.Password), v.Password) == 0)
{
int timeout = login.RememberMe ? 525600 : 20; // 525600 min = 1 year
var ticket = new FormsAuthenticationTicket(login.Username, login.RememberMe, timeout);
string encrypted = FormsAuthentication.Encrypt(ticket);
var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted);
cookie.Expires = DateTime.Now.AddMinutes(timeout);
cookie.HttpOnly = true;
Response.Cookies.Add(cookie);
if (Url.IsLocalUrl(ReturnUrl))
{
return Redirect(ReturnUrl);
}
else
{
FormsAuthentication.SetAuthCookie(login.Username, true);
Session["UserId"] = login.Username.ToString();
return RedirectToAction("Contact", "Home");
}
}
else
{
message = "Invalid credential provided";
}
}
else
{
message = "Invalid credential provided";
}
}
ViewBag.Message = message;
return View();
}
The View code is as follows:
#using Stimulsoft.Report.Mvc;
#using Stimulsoft.Report;
#{
ViewBag.Title = "ListPouyaProject";
Layout = "~/Views/Shared/_mainView.cshtml";
}
<section class="content">
<!-- Default box -->
<div class="box">
<div class="box-body">
<div class="form-group">
Start Date: <input type="text" id="date1" name="date1" onclick="PersianDatePicker.Show(this, '1392/03/22');" />
End Date : <input type="text" id="date2" name="date2" onclick="PersianDatePicker.Show(this, '1397/03/22');" />
</div>
<div class="form-group">
#Html.Stimulsoft().StiMvcViewer(new StiMvcViewerOptions()
{
Actions =
{
GetReport = "Report4_ListPouyaProject",
ViewerEvent = "ViewerEvent"
}
})
</div>
</div>
</div>
</section>
The Controller code is as follows:
public ActionResult Report4_ListPouyaProject()
{
var report = new StiReport();
report.Load(Server.MapPath("~/Content/Reports/ListPouyaProject.mrt"));
return StiMvcViewer.GetReportResult(report);
}
public ActionResult ListPouyaProject()
{
return View();
}
public ActionResult ViewerEvent()
{
return StiMvcViewer.ViewerEventResult();
}
I want to pass the date1 and date2 variables to the controller from view.
To do this, we need to add the following commands to the contoroller :
report.CompiledReport.DataSources["spm_report_4_ListPouyaProject"].Parameters["StartDate"].ParameterValue = DateTime.Parse(date1);
report.CompiledReport.DataSources["spm_report_4_ListPouyaProject"].Parameters["EndDate"].ParameterValue = DateTime.Parse(date2);
How to pass the parameters date1 and date2 from view to controller?
First, you need to add the StiMvcViewer component to the view page. Also, you need to pass the StiMvcViewerOptions object to the constructor. The minimum required options are two actions - GetReport and ViewerEvent, they are located in the Actions options group.
#using Stimulsoft.Report.MVC;
#Html.Stimulsoft().StiMvcViewer(new StiMvcViewerOptions()
{
Actions =
{
GetReport = "GetReport",
ViewerEvent = "ViewerEvent"
}
})
<div style="width: 150px;">
#Html.ActionLink("Simple List", "Index", new { id = "1" })
<br />Report Snapshot
</div>
and in controoller :
public ActionResult GetReport(int? id)
{
// Create the report object
StiReport report = new StiReport();
switch (id)
{
// Load report snapshot
case 1:
// Load report
// Load report snapshot
report.LoadDocument(Server.MapPath("~/Content/Reports/SimpleList.mdc"));
break;
}
// Load data from XML file for report template
if (!report.IsDocument)
{
DataSet data = new DataSet("Demo");
data.ReadXml(Server.MapPath("~/Content/Data/Demo.xml"));
report.RegData(data);
}
return StiMvcViewer.GetReportResult(report);
}
public ActionResult ViewerEvent()
{
return StiMvcViewer.ViewerEventResult();
}
I have an MVC template and I have 2 user roles, only users with these role can see and click the listItem in the navigationbar. But since all the roles can see it, it's enough to just not show it to non logged in people. This is my cshtml
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>#Html.ActionLink("Home", "Index", "Home")</li>
<li>#Html.ActionLink("Roles", "Index", "Roles")</li>
<li>#Html.ActionLink("Evaluaties", "About", "Home")</li>
</ul>
#Html.Partial("_LoginPartial")
</div>
So the last listItem Evaluaties should not be seen by not logged in people or in other word only by the two roles Student (Leerling) and Teacher (Begeleider). Which are used in my Controller.
public ActionResult About()
{
if (User.IsInRole("Begeleider"))
{
var client = new WebClient();
var jsonLeerlingen = client.DownloadString(new Uri("http://localhost:8080/projecten/api/leerlingen"));
var leerlingen = Newtonsoft.Json.JsonConvert.DeserializeObject<IEnumerable<Leerling>>(jsonLeerlingen);
var jsonEvaluaties = client.DownloadString(new Uri("http://localhost:8080/projecten/api/evaluaties"));
var evaluaties = Newtonsoft.Json.JsonConvert.DeserializeObject<IEnumerable<Evaluatie>>(jsonEvaluaties);
ViewBag.Message = leerlingen;
ViewBag.Evaluaties = evaluaties;
}
if (User.IsInRole("Leerling"))
{
var email = User.Identity.GetUserName();
var client = new WebClient();
var jsonLeerlingen = client.DownloadString(new Uri("http://localhost:8080/projecten/api/leerlingen"));
var leerlingen = Newtonsoft.Json.JsonConvert.DeserializeObject<IEnumerable<Leerling>>(jsonLeerlingen);
var jsonEvaluaties = client.DownloadString(new Uri("http://localhost:8080/projecten/api/evaluaties"));
var evaluaties = Newtonsoft.Json.JsonConvert.DeserializeObject<IEnumerable<Evaluatie>>(jsonEvaluaties);
ViewBag.Message = leerlingen;
ViewBag.Evaluaties = evaluaties;
}
return View();
}
i tried with if (User.IsInRole("Begeleider")) but I can't use that in a.cshtml page
If you take a look inside the _LoginPartial.cshtml partial view, you will see something implemented in exactly the same way you are trying to do it. So for example:
#if (Request.IsAuthenticated)
{
<div>You are logged in</div>
}
else
{
<div>You are not logged in</div>
}