public int SaveBlah([FromBody] Object blah)
{
var jsonString = blah.ToString();
Blah result = JsonConvert.DeserializeObject<B;ah>(jsonString);
}
Showing posts with label MVC. Show all posts
Showing posts with label MVC. Show all posts
Thursday, August 16, 2018
Thursday, April 26, 2018
if you are getting your json through a get
remember
return Json(result,JsonRequestBehavior.AllowGet);
return Json(result,JsonRequestBehavior.AllowGet);
JSON - A circular reference was detected while serializing an object of type 'System.Reflection
var result = JsonConvert.SerializeObject(ds, Formatting.Indented,
new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
});
return Json(result,JsonRequestBehavior.AllowGet);
new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
});
return Json(result,JsonRequestBehavior.AllowGet);
Thursday, May 21, 2015
mapping fake routes in MVC
routes.MapRoute(
"Boris",
"Boris/Show",
new
{
controller = "Herby",
action = "Index"
}
);
"Boris",
"Boris/Show",
new
{
controller = "Herby",
action = "Index"
}
);
Simple MVC Filter
public class TestFilter : ActionFilterAttribute
{
public override void OnActionExecuted(ActionExecutedContext
filterContext)
{
base.OnActionExecuted(filterContext);
System.IO.File.AppendAllText(@"c:\log.txt", string.Format("{0}\r\n",
filterContext.RequestContext.HttpContext.Request.Url.ToString()));
}
}
In global.asax:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
GlobalFilters.Filters.Add(new TestFilter());
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
Thursday, January 15, 2015
Downloading Files in MVC where excel is not actually opened
I inherited from FileResult and it did not download - even though I set download name
I did this and it works
public FileResult DownloadTextAsAFile(string data, string name)
{
string fileName = string.Format("{0}.csv", name);
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(data);
return new FileContentResult(bytes, "application/vnd.ms-excel") { FileDownloadName = name };
}
I did this and it works
public FileResult DownloadTextAsAFile(string data, string name)
{
string fileName = string.Format("{0}.csv", name);
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(data);
return new FileContentResult(bytes, "application/vnd.ms-excel") { FileDownloadName = name };
}
Monday, September 22, 2014
Could not load type MvcApplication
just restarted VS
Tuesday, January 14, 2014
C# MVC Interview Questions
- what is the vital difference between standard aspx requests and MVC requests?
- does mvc correspond to 3-tier architecture?
- why would a route need the following:
- when does the routing table get initiated?(application start event)
- what is the purpose of areas?
- can an mvc application have plain asp.net pages?
- can you use httpModules in MVC?
Thursday, November 14, 2013
Tuesday, October 22, 2013
mvc http 500 errors
check the passed parameters - the procedure will never be hit
Wednesday, October 2, 2013
MVC Routes
products/5 and products?id=5 are equivelent
Tuesday, July 30, 2013
Get IE to display JsonResult instead of prompt to download
return
Json(bm, "text/html", JsonRequestBehavior.AllowGet);
Html.ValidationSummary always showing
added this to fix
<style type ="text/css">
.validation-summary-valid { display:none; }
</style>
<style type ="text/css">
.validation-summary-valid { display:none; }
</style>
[ControllerAction] deprecated and illegal
use [NonAction] instead
Monday, July 29, 2013
inserting partial views
<% Html.RenderPartial("heh"); %>
Parser Error Message: The type 'System.Web.Mvc.ViewPage' is ambiguous
fixed it thus:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="2.0.0.0" newVersion="4.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
Difference Between ViewBag & ViewData
Controller
[HttpGet]
public ActionResult HerbyList()
{
HerbyModel
hm = new HerbyModel();
ViewData["HerbyList"]
= hm.Herb;
ViewBag.HerbyList = hm.Herb;
return
View();
}
// this.GridView1.DataSource =
(DataTable)ViewData["HerbyList"];
this.GridView1.DataSource
= ViewBag.HerbyList;
this.GridView1.DataBind();
Subscribe to:
Comments (Atom)