When I run the application I got error “CS1003: Syntax error, '>' expected”. After that I realized the mistake because of semicolon (;) I put after the model class in the Index.cshtml view “@model MVC_tutorials.Models.Document;”
Controller:
namespace MVC_tutorials.Controllers
{
public class docController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(docfile document)
{
string fileName = Server.MapPath(@"~\DocXExample.docx");
// Create a document in memory:
var doc = DocX.Create(fileName);
// Insert a paragrpah:
doc.InsertParagraph(document.txtContent);
// Save to the output directory:
doc.Save();
TempData["Message"] = "document created successfully.";
return View();
}
}
}
Index View:
@model MVC_tutorials.Models.docfile;
@{
ViewBag.Title = "create document in asp.net MVC";
}
<div style="padding-top: 15px">
<h2 style="color: #FF5722">create document in asp.net MVC
</h2>
@using (@Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
if (TempData["Message"] != null)
{
<p style="font-family: Arial; font-size: 16px; font-weight: 200; color: #56772F">@TempData["Message"]</p>
}
@Html.TextAreaFor(model => model.txtContent, new { Class = "mytextstyle", rows = 5, Style = "width:450px", placeholder = "type your content and save it in a document." })
<br />
<input type="submit" value="create document" class="btn" />
}
</div>
class model:
namespace MVC_tutorials.Models
{
public class docfile
{
public string txtContent { get; set; }
}
}
Excepition:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1003: Syntax error, '>' expected
Line 28:
Line 29:
Line 30: public class _Page_Views_doc_Index_cshtml : System.Web.Mvc.WebViewPage<MVC_tutorials.Models.Document;> {
Line 31: Line 32: #line hidden
Source Error:
Source File: c:\Users\RASIK\AppData\Local\Temp\Temporary ASP.NET Files\root\6c0b9ec1\5701cd39\App_Web_index.cshtml.b7021bbc.adqk_5r2.0.cs Line: 30
Solution:
Index view:
@model MVC_tutorials.Models.docfile;
Change it to
@model MVC_tutorials.Models.docfile