Hi @kadir,
there is a problem, I cannot properly pdf the data entered by the user.
I briefly tested your code and it works fine. Based on your description, you should be able to successfully get the value. What does the PDF you generated look like?
First, you can check whether the value was successfully retrieved.
If you cannot find the PDF file in the solution directory in VS, you will need to click "Show All Files" to display the file,then right click "Include In Project".
This is the code I tested:
public ActionResult Create()
{
var model = new csbasvurular();
return View(model);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult create(csbasvurular csbasvurularr)
{
string mesaj = "", mesajOk = "";
if (ModelState.IsValid)
{
int newlyCreatedId = csbasvurularr.TBL_GenelBilgi.GenelBilgiid;
string pdfPath = CreatePDF(csbasvurularr, newlyCreatedId);
var pdfEntry = new TBL_Pdf
{
PdfNeme = pdfPath,
GenelBilgiid = newlyCreatedId,
isDelete = false
};
mesajOk = "Başvurunuz alınmıştır.";
return RedirectToAction("create", new { mesajOk });
}
return RedirectToAction("create", new { mesajOk });
}
public string CreatePDF(csbasvurular csbasvurularr, int? newlyCreatedId)
{
Document document = new Document();
Random random = new Random();
int randomNumber = random.Next(10000, 99999);
string fileName = $"{csbasvurularr.TBL_GenelBilgi.Ad + "-" + csbasvurularr.TBL_GenelBilgi.Soyad}_{newlyCreatedId}_{randomNumber}.pdf";
string path = Server.MapPath("~/pdf/" + fileName);
PdfWriter.GetInstance(document, new FileStream(path, FileMode.Create));
document.Open();
// Başlık
Font titleFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 16);
Paragraph title = new Paragraph($"{csbasvurularr.TBL_GenelBilgi.Ad} {csbasvurularr.TBL_GenelBilgi.Soyad} İş Başvurusu", titleFont);
title.Alignment = Element.ALIGN_CENTER;
document.Add(title);
PdfPTable personalTable = new PdfPTable(2);
personalTable.AddCell("Ad:");
personalTable.AddCell(csbasvurularr.TBL_GenelBilgi.Ad);
personalTable.AddCell("Soyad:");
personalTable.AddCell(csbasvurularr.TBL_GenelBilgi.Soyad);
personalTable.AddCell("E-Mail:");
personalTable.AddCell(csbasvurularr.TBL_GenelBilgi.Email);
personalTable.AddCell("Telefon:");
personalTable.AddCell(csbasvurularr.TBL_GenelBilgi.Tel);
document.Add(personalTable);
document.Close();
return fileName;
}
public class csbasvurular
{
public TBL_GenelBilgi TBL_GenelBilgi { get; set; }
}
public class TBL_GenelBilgi
{
public int GenelBilgiid { get; set; }
public string Ad { get; set; }
public string Soyad { get; set; }
public string Email { get; set; }
public string Tel { get; set; }
}
@model MVCDemo.Models.csbasvurular
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>TBL_GenelBilgi</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div id="education-seminar-forms">
<div class="form-group">
@Html.LabelFor(model => model.TBL_GenelBilgi.GenelBilgiid, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.TBL_GenelBilgi.GenelBilgiid, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.TBL_GenelBilgi.GenelBilgiid, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.TBL_GenelBilgi.Ad, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.TBL_GenelBilgi.Ad, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.TBL_GenelBilgi.Ad, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.TBL_GenelBilgi.Soyad, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.TBL_GenelBilgi.Soyad, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.TBL_GenelBilgi.Soyad, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.TBL_GenelBilgi.Email, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.TBL_GenelBilgi.Email, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.TBL_GenelBilgi.Email, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.TBL_GenelBilgi.Tel, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.TBL_GenelBilgi.Tel, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.TBL_GenelBilgi.Tel, "", new { @class = "text-danger" })
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Submit" />
</div>
</div>
</div>
}
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.