4
I am using in my Windows Authentication application. I have a controller where the user should register their professional experiences. However, the way the application was made, I need every time I insert a new data, put the number plate or ID of it. How do I redeem or save the Perfilid (enrollment) that the application has already picked up when opening the program so that the user does not need to enter his Perfilid every time he or she enters something? You need to create a session or have a simpler way.
My view is like this:
@model Competências.Models.Experiencia
@Scripts.Render("~/bundles/validation")
@using (Ajax.BeginForm(new AjaxOptions
{
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST"
}))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<div class="col-md-4">
<b>Id</b>
@Html.TextBoxFor(model => model.Perfilid, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Perfilid)
</div>
</div>
<div class="modal-body row">
<div class="col-md-12">
@Html.LabelFor(model => model.Atividades)
@Html.TextBoxFor(model => model.Atividades, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Atividades)
</div> </div>
My controller:
public ActionResult Create()
{
return PartialView();
}
//// POST: /Experiencia/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(Experiencia experiencia)
{
db.Experiencia.Add(experiencia);
db.SaveChanges();
return RedirectToAction("Index");
}
Models:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
namespace Competências.Models
{
public class Experiencia
{
public int Id { get; set; }
[Required(ErrorMessage = "É obrigatório descrever as atividades desempenhadas na empresa")]
[StringLength(255, ErrorMessage = "O campo atividades pode ter no máximo 255 caracteres")]
public string Atividades { get; set; }
public int Perfilid { get; set; }
public virtual Perfil Perfil { get; set; }
Right. And this session or cookie I create inside a new controller or inside the controller where I want to rescue the information, in case, Experience?
– Victor
So: At the time you authenticate the user by windows in the same controller method you use Creating Session or Cookie. Now to recover you will in the Controller that already exists enters the method and uses the Recovering Session or Cookie, understood @Victor
– user6026
Got it! I’ll try here and anything else I ask for help again! hahaha Thanks for the help!
– Victor
At what point I do the attribution of what I picked up on Session with the Pk_id I want to insert?
– Victor
@Victor in Creating Session, I see the example, and when you want to recover this value is in Recovering Session
– user6026