I am using it in my Windows Authentication application. I have a controller where the user must register their professional experiences. However, the way the application was made, I need every time I enter a new data, put the license number or ID of it. How do I retrieve or save the perfilid (registration) that the application has already taken when opening the program so that the user does not have to type his Perfilid every time he inserts something? You need to create a session or have a simpler form.
My view looks 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; }